Skip to main content
EBonv
Associate III
September 10, 2019
Solved

How to add external libraries in STM32CubeIDE

  • September 10, 2019
  • 7 replies
  • 20040 views

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.

This topic has been closed for replies.
Best answer by KnarfB

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.

7 replies

KnarfB
KnarfBBest answer
Super User
September 11, 2019

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.

RHug.1
Associate II
March 5, 2020

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?

KnarfB
Super User
March 5, 2020

> 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

EBonv
EBonvAuthor
Associate III
September 11, 2019

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
Super User
September 11, 2019

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
EBonvAuthor
Associate III
September 12, 2019

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.

EBonv
EBonvAuthor
Associate III
September 11, 2019

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.

Wladimir
Associate II
May 7, 2021

Hello!

How can i include cryptolyb library .a files into STM32CubeIDE project?

Project doesn't recognize them for now. I put them in source directory in project files catalog.

0693W00000ANemuQAD.jpg 

0693W00000ANeo2QAD.jpg 

The following errors occur:

" ../Src/main.c:313: undefined reference to `RSA_PKCS1v15_Encrypt' "

" ../Src/main.c:297: undefined reference to `RNGinit' "

Then i followed instructions from best answer of this topic

0693W00000ANflJQAT.jpg 

And i got another errors:

" c:\st\stm32cubeide_1.4.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: error: STM32L476RG-Nucleo_PollingTagDetect_rbld.elf uses VFP register arguments, C:\git_repos\STM32L476RG-Nucleo_PollingTagDetect_rbld\Middlewares\ST\STM32_Cryptographic\Lib\libSTM32CryptographicV3.0.0_CM4_GCC.a(crypto.o) does not "

" :\st\stm32cubeide_1.4.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: failed to merge target specific data of file C:\git_repos\STM32L476RG-Nucleo_PollingTagDetect_rbld\Middlewares\ST\STM32_Cryptographic\Lib\libSTM32CryptographicV3.0.0_CM4_GCC.a(crypto.o) "

Best regards!

Cartu38 OpenDev
Graduate II
May 7, 2021

@Wladimir​ My 2 cents looking at your snashot. If 'Libraries (-l)' area takes care.

1) To add ':' char as first character of your library file

2) To add '.a' libray file extension ... full file name including extension as to be provided

Then possibly if linker process still fail reorder our library files ... GCC is order sensitive here ...

Wladimir
Associate II
May 7, 2021

Hello Cartu38 OpenDev,

Unfortunately, it didn't help, the error has changed, now can't find the library file. The path to the library file I tried is both absolute and relative to the workspace.

0693W00000ANiJNQA1.png 

The error is:

" c:\st\stm32cubeide_1.3.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: cannot find -l:STM32CryptographicV3.0.0_CM4_GCC.a "

Best regards, Vladimir

Wladimir
Associate II
May 8, 2021

Hello,

It doesn't help, same error, "can't find -l:STM32CryptographicV3.0.0_CM4_GCC.a"

0693W00000ANjYnQAL.png 

I entered the path string manually

Cartu38 OpenDev
Graduate II
May 8, 2021

@Wladimir​ works for me doing hash computation. Please get a try based on attached project (Please just add back to such delivery middlewares part I've removed because such crypto pack content delivery is under special legal terms ... just copy/paste from pack you have)

Note: I rely on STM32CubeIDE 1.6.1

0693W00000ANl42QAD.png

Wladimir
Associate II
May 8, 2021

Thanks, its builded without errors.

Don't understand what is my issue, i'll try to figure it out.

PHolt.1
Senior
July 26, 2022

"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."

This may have worked in 2019 but it does not appear to work now, Cube IDE v1.10.1.

I have a file called libc-weakened.a (basically the old libc.a but with the mutex symbols weakened using objcopy, so the completely useless empty mutex functions can be replaced with real ones) and can't get it to be recognised. It appears on the LD command line ok, although there is no space after the -l (it shows cannot find -lC:/KDE485/Project1/LIBC/libc-weakened.a) so I tried double quotes and a leading space, still with no luck.

0693W00000QMAdLQAX.png 

0693W00000QMAe9QAH.png