Skip to main content
Graduate II
April 3, 2024
Solved

Proper way to use a Library (.a)

  • April 3, 2024
  • 4 replies
  • 3211 views

Hi everyone,

Designing the BLE (bluetooth low energy) part of my software, I have to use BlueNRG-1, BlueNRG-2 DK SW package.

First of all, I included by hands the library file (.a).

But there is a lot of source-code that is not provided in the library (but in others files), I then decided to include manually headers file and others source code files (.c). Dont know if its a good practice.

Are their others options instead of manually including .a, .h and .c files ?

I recently realized that new versions of source code was available, and manually do migration every-time is error-prone and long to do.

Thanks for advice !

    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello,

    It's OK for the library.

    For includes, they are already seen in .c files.  You don't need to add it manually by drag and drop. All you need is to add the include path here:

    Example:

    SofLit_0-1712145742435.png

     

    For c file you can drag and drop to the project browser.

    If you are using CubeMx to generate code and you fear CubeMx will delete your c library files for each code generation, I suggest you to see my reply in this thread.

    To answer your first question: Are their others options instead of manually including .a, .h and .c files ?

    I don't think so. May you need to develop a script to handle this and update .cproject and .project.

     

     

     

    4 replies

    Technical Moderator
    April 3, 2024

    Hello,

    You didn't provide information about your cross compilation environment? Which toolchain?

    Graduate II
    April 3, 2024

    I compile my project under stm32cubeIDE with gcc

    I added the .a library file with -L flag under gcc (in project > settings > MCU GCC linker > libraries)

    I add the .h / .c files with the source code that is not included in the lib by drag and dropping files into stm32cubeIDE.

    mƎALLEmAnswer
    Technical Moderator
    April 3, 2024

    Hello,

    It's OK for the library.

    For includes, they are already seen in .c files.  You don't need to add it manually by drag and drop. All you need is to add the include path here:

    Example:

    SofLit_0-1712145742435.png

     

    For c file you can drag and drop to the project browser.

    If you are using CubeMx to generate code and you fear CubeMx will delete your c library files for each code generation, I suggest you to see my reply in this thread.

    To answer your first question: Are their others options instead of manually including .a, .h and .c files ?

    I don't think so. May you need to develop a script to handle this and update .cproject and .project.

     

     

     

    Super User
    April 3, 2024

    I added the .a library file with -L flag 

    Nope, the -L flag gives a *path* to the .a file.

    The .a file can be specified as -lbasename or -l:fullname .

    The latter form allows to specify filenames that are NOT in form libsomething.a

    The libraries can be also specified in the link script.

     

    Graduate II
    April 3, 2024

    what I understood is that gcc -L looks in directory for library files.

    So if there is a library file in the directory path, it will be included

    I'll read again the manual

    Graduate II
    April 3, 2024

    Ok thanks,

    I didnt knew I can include path content for header's file with gcc -I in stm32cubeIDE.
    That's what I was looking for !

    But I didnt get your point of fearing that cubeMX delete C code for a code generation ?

    I already manually added .c files in the Core/Src folder. So after reading your message I tried a code generation under cubeMX after a dummy change in the .ioc (just for see whats happen), and the code that I added manually is still here.

     

    Technical Moderator
    April 3, 2024

    Yes. It was just in case when CubeMx could remove them. The method I proposed is to tell and "insist" to CubeMx to add these files to your project without adding them by drag and drop.