ubuntu 中How to fix undefined reference to `sqrt' in Eclipse

Friday, September 23, 2011

How to fix undefined reference to `sqrt' in Eclipse

- Re: How to use math.h in Eclipse with gcc? [message #214058 is a reply to message #213974] Wed, 16 April 2008 04:50 Go to next message
Tracy Miranda is currently offline Tracy Miranda
Messages: 15
Registered: July 2009
Junior Member
 
Hi Warren,

The "-lm" option is a linker option - looks like you've added it to the 
Compiler 'Other flags', where it has no effect.
Add it to the linker options, Libraries-> add it in as a new library "m", 
this will automatically add on the -l to the option.
(Alternately, you can add "-lm" to the Miscellaneous->Linker Flags box, but 
I highly recommend the previous option).

Tracy

"Warren Tang" <[email protected]> wrote in message 
news:[email protected]...
>
> I tried to add the "-lm" option for gcc in the project properties:
> -c -fmessage-length=0 -std=c99 -lm
>
> However the eclipse still complains that:
> undefined reference to `sqrt'
>

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

你可能感兴趣的:(ubuntu 中How to fix undefined reference to `sqrt' in Eclipse)