Showing results for 
Search instead for 
Did you mean: 
Honored Contributor I

undefined reference to math.h functions in bsp project even with -lm

I have written a HAL driver for a custom Qsys component. This means the code compiles as part of the _bsp project, not the application project. If I use functions from math.h such as ceilf() from the _bsp project, then when I link the application, I get errors such as: 


inm_free_counter.c:(.text+0x48): undefined reference to `ceilf' 


i do have "-lm" specified in the project settings, as you can see below: 


make all Info: Building ../MVSD_Board_Test_Nios_bsp/ make --no-print-directory -C ../MVSD_Board_Test_Nios_bsp/ Info: Compiling main.c to obj/default/main.o nios2-elf-gcc -xc -MP -MMD -c -I../MVSD_Board_Test_Nios_bsp//HAL/inc -I../MVSD_Board_Test_Nios_bsp/ -I../MVSD_Board_Test_Nios_bsp//drivers/inc -DSYSTEM_BUS_WIDTH=32 -pipe -D__hal__ -DALT_NO_C_PLUS_PLUS -DALT_NO_CLEAN_EXIT -D'exit(a)=_exit(a)' -DALT_NO_EXIT -DALT_USE_DIRECT_DRIVERS -DALT_NO_INSTRUCTION_EMULATION -DALT_USE_SMALL_DRIVERS -DSMALL_C_LIB -DALT_SINGLE_THREADED -DALTERA_AVALON_JTAG_UART_SMALL -DFIFOED_AVALON_UART_SMALL -DALT_USE_DIRECT_DRIVERS -DALT_USE_EPCS_FLASH -Os -Wall -mno-hw-div -mno-hw-mul -mno-hw-mulx -o obj/default/main.o main.c ../MVSD_Board_Test_Nios_bsp/\libhal_bsp.a(inm_free_counter.o): In function `inm_fc_setOutput': Info: Linking MVSD_Sequencer_Test.elf inm_free_counter.c:(.text+0x48): undefined reference to `ceilf' collect2.exe: error: ld returned 1 exit status make: *** Error 1 nios2-elf-g++ -lm -T'../MVSD_Board_Test_Nios_bsp//linker.x' -msys-crt0='../MVSD_Board_Test_Nios_bsp//obj/HAL/src/crt0.o' -msys-lib=hal_bsp -L../MVSD_Board_Test_Nios_bsp/ -msmallc -Wl, -DALT_USE_DIRECT_DRIVERS -DALT_USE_EPCS_FLASH -Os -Wall -mno-hw-div -mno-hw-mul -mno-hw-mulx -o MVSD_Sequencer_Test.elf obj/default/main.o -lm  


This is only one example. Sometimes floorf() works but ceilf() doesn't; sometimes vice versa. I have another project that uses the same driver, and it does compile correctly. I'm using a NiosII/e. I have Quartus 13.1 Web Edition installed including Update 3. 


Why am I getting linker errors about the math library even with the "-lm" flag?
0 Kudos
0 Replies