-
compilation problem
I was doing the following program in RedHat-9 Linux, but the program is not getting complied, your help is sorted.
------------
#include<stdio.h>
#include<math.h>
int main()
{
double pie,theth,dis,velo=0.0;
printf("\nEnter the angle theta: ");
scanf("%lg",&theth);
printf("\n Enter the angle pie: ");
scanf("%lg",&pie);
printf("\nEnter the velocity of the projectile: ");
scanf("%lg",&velo);
pie=3.1415927/180.0*pie;
theth=3.1415927/180.0*theth;
dis=2.0*velo*velo*cos(theth)*cos(theth)*(tan(theth)-tan(pie)/(9.81 * cos(pie)));
printf("\nThe Distance is: %g",dis);
return 0;
}
------------------------------------------
the following command is used to compile the program.
-------------------------
gcc projectile.c
-------------------------
it shows the following output on the screen, I do not what it means and needs to be done.
-------------------------------------------------------------------------
/tmp/ccC2282K.oC.text+0xbb): In function ‘main’
: undefined reference to ‘cos’
/tmp/ccC2282K.oC.text+0xd4): In function ‘main’
: undefined reference to ‘cos’
/tmp/ccC2282K.oC.text+0xed): In function ‘main’
: undefined reference to ‘tan’
/tmp/ccC2282K.oC.text+0x101): In function ‘main’
: undefined reference to ‘tan’
/tmp/ccC2282K.oC.text+0x11d): In function ‘main’
: undefined reference to ‘cos’
--------------------------------------------------------------------
Thank you for your time and patience.
-
gcc -lm projectile.c
http://lists.trolltech.com/qt-intere...ad00056-0.html
Don't ask me what the -lm means but it works.
I compiled it and it runs.
:cool:
-
Using the -lm option makes the linker include the math library as far as I can tell. Basically what the error messages were saying is that the compiler couldn't find the function/variable (function in this case) name for some reason. This is because for some reason you have to manually include the math library.
Also, in case you didn't know this already, you can use the -o switch if you want the binary file's name to be different from the source file:
Code:
gcc test.c -o test
or
gcc test.c -o sflkjs
Anyhow...that was beside the point.
ac
-
I've had this problem in the past too while using the sqrt() function. I never knew about the -lm though. Thanks rcgreen :)
-
Thanks guys, it your knowledge sharing was definately of help.