LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2004, 05:25 PM   #1
harbir
LQ Newbie
 
Registered: Jan 2004
Posts: 18

Rep: Reputation: 0
compilling 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.
 
Old 07-09-2004, 05:28 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
You need to link in the math library. Try the following command to compile your program: gcc projectile.c -lm

It should produce an executable file called a.out
 
Old 07-09-2004, 05:30 PM   #3
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
Yeah, this happens to everybody the first time they try to use anything in math.h You need to compile like this:

Code:
gcc -lm projectile.c
-l is for link, and m means to link libm, the math library.
 
Old 07-09-2004, 05:36 PM   #4
harbir
LQ Newbie
 
Registered: Jan 2004
Posts: 18

Original Poster
Rep: Reputation: 0
thanks guys i will just try it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] compilling apache lord_didger Linux - Software 2 09-03-2005 06:38 AM
compilling 2.6.7 kernel Help props666999 Linux - General 2 11-12-2004 08:15 PM
Problems compilling sign-1.0.7 Adony Linux - Software 0 10-08-2004 08:37 PM
error after compilling kernel greklas Slackware 2 09-06-2004 01:53 PM
compilling kernel 2.4.18 gusgorman Linux - General 2 06-18-2002 03:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration