Forum Discussion
Altera_Forum
Honored Contributor
13 years agoproblem with math.h 's function in Eclipse
hello,
I made a system with Qsys which just contain a Nios II processor and its On-chip-memory. then , I use the .sopcinfo File generated by Qsys to create a nios II application with Eclipse. My problem is that I didn't succeed in using the library math.h I wrote the following simple code : # include <stdio.h># include <math.h> int main() { double result =5; result = floor(result); return 0; } And I obtain the error : undefined reference to `floor' main.c /testnios line 24 C/C++ Problem Do you have any idea about my problem or what I did wrong ? thank you7 Replies
- Altera_Forum
Honored Contributor
Hi,
Try to set additional linker key: -lm http://cboard.cprogramming.com/c-programming/45664-gcc-math-h.html - Altera_Forum
Honored Contributor
Gotta link it against the library libm... "-lm" needs to be added at the tail end of your compilation command. This is not specific to Nios II. It wouldn't work with any GCC compiler without linking against libm.
- Altera_Forum
Honored Contributor
thank you slacker,
Do you or someone else knows where I can edit the compilation command ? I didnt find in project->properties thanks - Altera_Forum
Honored Contributor
Hi,
I have the same problem with Quartus 13 / Nios II EDS 13.0. It's a linker error. You can try to add manualy "-lm" option for the linker but no effect on my computer. http://www.kirikoo.net/images/14Anonyme-20130716-104232.png**** Build of configuration Nios II for project test_math **** make all Info: Building D:/test_math_bsp/ make --no-print-directory -C D:/test_math_bsp/ Info: Compiling hello_world.c to obj/default/hello_world.o nios2-elf-gcc -xc -MP -MMD -c -ID:/test_math_bsp//HAL/inc -ID:/test_math_bsp/ -ID:/test_math_bsp//drivers/inc -DSYSTEM_BUS_WIDTH=32 -pipe -D__hal__ -DALT_NO_INSTRUCTION_EMULATION -DALT_SINGLE_THREADED -O0 -g -Wall -EL -mhw-div -mhw-mul -mhw-mulx -o obj/default/hello_world.o hello_world.c hello_world.c: In function 'main': hello_world.c:23: warning: unused variable 'test' Info: Linking test_math.elf nios2-elf-g++ -T'D:/test_math_bsp//linker.x' -msys-crt0='D:/test_math_bsp//obj/HAL/src/crt0.o' -msys-lib=hal_bsp -LD:/test_math_bsp/ -Wl,-Map=test_math.map -O0 -g -Wall -EL -mhw-div -mhw-mul -mhw-mulx -o test_math.elf obj/default/hello_world.o -lm obj/default/hello_world.o: In function `main': D:\test_math/hello_world.c:23: undefined reference to `cos' collect2: ld returned 1 exit status make: *** Error 1 **** Build Finished ****
It seems Altera has some problems with tests before releasing theirs softwares...# include <stdio.h># include <math.h> int main() { printf("Hello from Nios II!\n"); double test = cos(3.14); return 0; } - Altera_Forum
Honored Contributor
Thanks you force-pc
I tried but there is no effect on my computer too. I work also with Quartus 13 / Nios II EDS 13.0. - Altera_Forum
Honored Contributor
Hi LETS,
I try to read differents posts on the web like: http://stackoverflow.com/questions/7824439/c-math-linker-problems-on-ubuntu-11-10 http://stackoverflow.com/questions/16344445/im-using-math-h-and-the-library-link-lm-but-undefined-reference-to-pow-st http://stackoverflow.com/questions/8480013/eclipse-c-c-cdt-add-l-option-linking-math-module-gcc-lm The generated Makefile seems to be good because Eclipse places the -lm argument at the end... I'm now installing Quartus 13.0sp1 to see if the problem persists. - Altera_Forum
Honored Contributor
==>> No more problem with 13.0sp1. F***ing software!
==>> Don't use 13.0 with math.h lib & nios II.