Hello and special greetings to all linuxquestions.org regulars.
This is my first post here, so please be gentle.
I have subscribed to a computer course which has object to teach us
ANSI C.
In one of the example the is supposed to be a program that displays some mathematic table containing both angles and relevant sins.
The source file
angles-sins.c has the following line:
When I tried to compiled it I typed:
Code:
debian-sarge:~ # gcc -x c angles-sins.c
Then I was fed with an error that said that there were no reference on the function sin which is in the source file.
I edited the source file and made that include line to look like this:
Code:
#include </usr/share/include/math.h>
In case the linker had problem finding the file math.h but still it didn't work.
Reading more carefully my notes I saw that in order to have this compiled you have to to type:
Code:
debian-sarge:~ # gcc -x c angles-sins.c -lm
Which instructs the linker to include the math function library.
The compilation runs error-free this way.
Being more curious I removed the:
line completely and when I typed:
Code:
debian-sarge:~ # gcc -x c angles-sins.c -lm
it compiled again.
My question is:
Why do I have to type the
line in my source code when only by using:
Code:
debian-sarge:~ # gcc -x c foo.c -lm
gets my compilation done?