c - undefined reference to sqrt (or other mathematical functions) -


i have simple code:

max = (int) sqrt (number); 

and in header have:

#include <math.h> 

but application still says undefined reference sqrt. see problem here? looks should okay.

you may find have link math libraries on whatever system you're using, like:

gcc -o myprog myprog.c -l/path/to/libs -lm                                        ^^^ - bit here. 

including headers lets compiler know function declarations not automatically link code required perform function.

failing that, you'll need show code, compile command , platform you're running on (operating system, compiler, etc).

the following code compiles , links fine:

#include <math.h> int main (void) {     int max = sqrt (9);     return 0; } 

just aware some compilation systems depend on order in libraries given on command line. that, mean may process libraries in sequence , use them satisfy unresolved symbols at point in sequence.

so, example, given commands:

gcc -o plugh plugh.o -lxyzzy gcc -o plugh -lxyzzy plugh.o 

and plugh.o requires xyzzy library, second may not work expect. @ point list library, there no unresolved symbols satisfy.

and when unresolved symbols plugh.o do appear, it's late.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -