cancel
Showing results for 
Search instead for 
Did you mean: 

How to add external libraries in STM32CubeIDE

EBonv
Associate III

Hi, I'd like to know if it is possible to add external libraries on STM32CubeIDE and if yes, how.

In particular, I'd like to use cryptographic functions on my NUCLEO-H753ZI. And I found a library on the web I could use in the form of an archive file (.a) + a header file. How can I integrate this archive in my project so I can use the functions of the library ?

Thank you in advance for your answer.

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

Hi,

under Project > Properties > C/C++ Build > Settings > Tool Settings > MCU GCC Linker > Libraries add the .a library name and the path to that file. This shall make the linker happy. Note that you don't enter the "lib" prefix and the extension .a, e.g. when the filename is libmylib.a, enter mylib

Besides, under MCU GCC Compiler > Include paths add the path to the header files to make the compiler happy.

You may keep copies of the .a and .h files within the project folder tree or "out-of-tree" in a separate folder as you prefer.

Note that .a files may exist for different MCU/CPU architectures and ABIs like floating point. Make sure that you get the correct libray linked in.

View solution in original post

20 REPLIES 20
KnarfB
Principal III

Hi,

under Project > Properties > C/C++ Build > Settings > Tool Settings > MCU GCC Linker > Libraries add the .a library name and the path to that file. This shall make the linker happy. Note that you don't enter the "lib" prefix and the extension .a, e.g. when the filename is libmylib.a, enter mylib

Besides, under MCU GCC Compiler > Include paths add the path to the header files to make the compiler happy.

You may keep copies of the .a and .h files within the project folder tree or "out-of-tree" in a separate folder as you prefer.

Note that .a files may exist for different MCU/CPU architectures and ABIs like floating point. Make sure that you get the correct libray linked in.

EBonv
Associate III

Thank you for your very clear answer.

However I still have a problem, building fails with the following error message :

[...]mylib.a: error adding symbols: File format not recognized

Do you, by any chance, have any input on this error ? Maybe there's still something missing with the configuration or something wrong with my archive file.

KnarfB
Principal III

maybe the .a file is not for the machine type you are using, or it is broken?

> And I found a library on the web

There is an optimized X-CUBE-CRYPTOLIB available from ST, it should support what you need.

EBonv
Associate III

Yes maybe, I don't see anything else.

I will test the library you proposed, I already tested the STM32-CRYP-LIB but it didn't seem to be made for my board.

Here is an update for other users who might run into the similar issue : for cryptography on the H7 generation of the nucleo boards, it is necessary to download the patch of the X-CUBE-CRYPTOLIB to find the necessary library. The libraries are not compatible between different generations and libraries other than ST ones do not seem to be compatible with ST products either.

Thank you KnarfB for your help.

What if there are no .a files in the library?

I would like to add following library but am uncertain how.

Adding it to the Project Directory within "Middlewares/Thrid_Party/"

and adding it within Project Properties -> C/C++ Build -> Settings -> Tool Setings-> MCU G++ Linker -> Libraries (Search path & Libraries using the Workspace path

Ends in Errors when building "no such file or directory"

Any help what I am doing wrong?

> What if there are no .a files in the library?

What else is in the library?

Note that if the file name is libBlaBla.a you only enter BlaBal . The lib prefix and the .a suffix will be added by the tools. See https://en.wikipedia.org/wiki/Library_(computing)#Most_modern_Unix-like_systems

Sorry was missing infos in my last post.

Library: https://github.com/epsilonrt/libmodbuspp

OS: Windows

IDE: STM32CubeIDE v1.3

Hi @RHug.1​ have you managed to successfully integrate this library in the end? This is not a TouchGFX issue but I am interested in the answer and the good continuity of your project.