Friday, September 23, 2011

How to fix undefined reference to `sqrt' in Eclipse

Math.h problem
Programming in C using Eclipse in Linux is great, however when i added variables that were doubles into the "sqrt" function from the "math.h" library there was a problem that came up.
undefined reference to `sqrt'
After a little bit of research, in Eclipse, go to Project > Properties > C/C++ Build > Settings > GCC C Linker > Miscellaneous > add "-lm" to the "Linker Flags" text field. That way it is properly linked to the project.
http://cboard.cprogramming.com/c-programming/88943-undefined-reference-sqrt.html

6 comments:

  1. Thank you for help!

    ReplyDelete
  2. Thank you so much!
    you helped me a lot!!!

    ReplyDelete
  3. Adicione no final da linha, conforme abaixo -lm -lc e lnosys

    $(EXECUTABLE): $(SRC) $(STARTUP) $(CC) $(CFLAGS) $^ -lm -lc -lnosys -o [email protected]

    http://www.eevblog.com/forum/microcontrollers/stm32f4-arm-none-eabi-gcc-not-linking-to-math/

    ReplyDelete

Please make suggestions :)