I'm learning C and found this problem. the following code:
/* sqroot.c */
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:
/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:
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,
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)":
printf("The square root of %lf is %lf\n", x, sqrt(15.0));
in the above programm work without the -lm option?