-
July 9th, 2004, 11:18 PM
#1
Senior Member
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.
U get What U pay for.
-
July 10th, 2004, 03:03 PM
#2
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.
I came in to the world with nothing. I still have most of it.
-
July 10th, 2004, 09:47 PM
#3
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
-
July 11th, 2004, 12:40 AM
#4
I've had this problem in the past too while using the sqrt() function. I never knew about the -lm though. Thanks rcgreen
-
July 11th, 2004, 03:13 AM
#5
Senior Member
Thanks guys, it your knowledge sharing was definately of help.
U get What U pay for.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|