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.