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.


  1. Thank you for help!

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

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

    $(EXECUTABLE): $(SRC) $(STARTUP) $(CC) $(CFLAGS) $^ -lm -lc -lnosys -o $@


Please make suggestions :)