Hello together,

I'm learning C and found this problem. the following code:

Code:

/* sqroot.c */
#include <stdio.h>
#include <math.h>
int main()
{
double x, y;
x = 15.0;
printf("The square root of %lf is %lf\n", x, sqrt(x));
}

does not compile, the error-message is:

Code:

/tmp/ccio1OHj.o: In function `main':
sqroot.c:(.text+0x34): undefined reference to `sqrt'
collect2: ld gab 1 als Ende-Status zurück

with the following command:

Code:

gcc -o sqroot sqroot.c

With the search funktion of this forum I found this thread:

http://www.linuxquestions.org/questi...rt#post3737549 which suggests to use the -lm option with gcc, this works for me,

Code:

gcc -lm -o sqroot sqroot.c

but what does this option mean for gcc? In the manpage of gcc there is an explanation of an -l option for the linker but I don't think that it is the same as -lm.

Another question is: why does "sqrt(15.0)" instead of "sqrt(x)":

Code:

printf("The square root of %lf is %lf\n", x, sqrt(15.0));

in the above programm work without the -lm option?

Markus