cancel
Showing results for 
Search instead for 
Did you mean: 

Proper way to use a Library (.a)

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 !

9 REPLIES 9
SofLit
ST Employee

Hello,

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

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

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.

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.

 

 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Pavel A.
Evangelist III

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.

 

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.

 

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

Ok thank you very much, I had missunderstood the gcc manual

I thought there was two way of including a lib.a with -L and -l.

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.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

It can be confusing. The C compiler include path option is capital i and the linker library *name* option is small L.

But both options can be on the gcc command line when gcc is used to invoke the ld linker (gcc can act as both C compiler and linker... oh my. And the linker also can have include files, in its linker scripts...).