In simplicity studio, I use the standard C math functions such as 'cos', 'sin', etc. I include the <math.h> header in my source file, it is successfully compiled. However, when linking and building, the console displays following errors:
D:\SiliconLabs\SimplicityStudio\v2\workspace\PPG\GNU ARM 4.7.3 - Debug/../src/main.c:64: undefined reference to `cos'
D:\SiliconLabs\SimplicityStudio\v2\workspace\PPG\GNU ARM 4.7.3 - Debug/../src/main.c:65: undefined reference to `sin'
As I know, the math functions are implemented in the library 'libm.a', so I add the library file in Property -> GNU ARM C Linker -> Libraries -> Add, "D:\SiliconLabs\SimplicityStudio\v2\developer\toolchains\gnu_arm\4.7_2013q1\arm-none-eabi\lib\libm.a"
However, when building, simplicity studio says:
d:/siliconlabs/simplicitystudio/v2/developer/toolchains/gnu_arm/4.7_2013q1/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/bin/ld.exe: cannot find -lD:\SiliconLabs\SimplicityStudio\v2\developer\toolchains\gnu_arm\4.7_2013q1\arm-none-eabi\lib\libm.a
The 'libm.a' file is located in the correct directory. I also tried other methods to include the 'libm.a', such as copy the lib file in the emlib dir of my workspace. All tries are failed. Anyone please give me some recommendations.
Thanks very much.
When you add a library to a project in Simplicity Studio under the linker settings, you need to remove the "lib" and the ".a" from the library's name. In this case, you should add "m" to your linker library settings.
Also do not include the full path. The library directory is already in the standard library search path. The final switch should look like '-lm'.
Thanks, it works.
Only to add 'm' in GNU C Linker -> Libraries -> Add ...
Yes, the linker used with GCC somehow thinks every library should start with 'lib' and you should tell it about it without using the 'lib' prefix. I find this one of the stupid peculiarites of the linker, but I'm afraid we'll have to work with it.
i had the same problem when i built the project: undefined reference to sin and cos functions, how can i modify the libm.a file in C: \ SiliconLabs \ SimplicityStudio \ v2 \ developer \ toolchains \ gnu_arm \ 4.8_2013q4 \ arm -none-eabi \ lib to getting all things working , or there something to add to the workstation project?
thank's in advance
I am running into the same problem. I would like to use the log function in the math.h library.
Where exactly is the Property-> GNU ARM C Linker->Libraries->Add??
I can only right click on my project, select Properties......but I don't see any GNU ARM C Linker option... I am so lost. Please help!
Ok. I found it. For those who may run into the same problem in the future too, here is the location:
Right Click Project -> Properties -> C/C++ Build -> Settings -> GNU ARM C Linker -> Libraries
I have the same problem but me its a function inside my own library that i want link with my project.
I use GNU 4.9.3, simplicity studio with Eclipse like a IDE.
Do you have possibility of solutions?
(Sorry for my aproxiamte English)
What is the name of your library on disk? It should start with 'líb' and then you must tell the linker to use that name without the 'lib' prefix.
Yes i know, i past the line code invoking linker:
Invoking: GNU ARM C Linker
arm-none-eabi-gcc -g -gdwarf-2 -mcpu=cortex-m3 -mthumb -T "APP_LightClicKW.ld" -L"C:\Users\user\SimplicityStudio\v4_workspace\APP_LightClicKW\Library" -LC:/RTX/reptile/RTX/LIB/GCC/ -Xlinker --gc-sections -Xlinker -Map="APP_LightClicKW.map" --specs=nano.specs -o APP_LightClicKW.axf -Wl,--start-group -lRTX_CM3 -lModuleIP -Wl,--end-group -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group
As you can see, i linked two lib. The first one is mine "ModuleIP" and the second one is RTX_CM3.
I take care about the gcc syntax
My problem is about my library.
Not sure if below KB helps:
Thanks, but this tutorial explaines exactly what i did.
The problem its somethings else !
I think the particularity of my situation is the fact i have the declarations in my static library but the functions are defined in my project
I've experienced this problem and the solution didn't completely solved the problem. After adding the m to the libraries I was still getting the undefined reference error message. I had to go to the GNU ARM C Linker > Ordering option (below the Libraries option) and move the -lm to the end of that list.
Hope it helps.