compiler unable to find defn. of sin()

S

sudip

Dear All,
I'm having a nightmare compiling a small simple program on a Linux
Fedora core 2 platform...the program goes like this...

in file mathtest.c

#include <math.h>
#include <stdio.h>

int main(void)
{
printf("%s%d\n","The value of sin(3) is: ", sin(3));
return 0;
}

I'm compiling the above program by issuing the following command on
bash shell...

gcc -Wall -o mathtest mathtest.c

the compiler is throwing the following error

in function 'main':
:undefined reference to 'sin'

....and stops the compilation process..
I'm stuck up, and can't figure out the error..plz help
 
A

Artie Gold

sudip said:
Dear All,
I'm having a nightmare compiling a small simple program on a Linux
Fedora core 2 platform...the program goes like this...

in file mathtest.c

#include <math.h>
#include <stdio.h>

int main(void)
{
printf("%s%d\n","The value of sin(3) is: ", sin(3));
return 0;
}

I'm compiling the above program by issuing the following command on
bash shell...

gcc -Wall -o mathtest mathtest.c

the compiler is throwing the following error

in function 'main':
:undefined reference to 'sin'

...and stops the compilation process..
I'm stuck up, and can't figure out the error..plz help
This is a FAQ. Find it. Read it. It's not that hard. (And doing so will
serve you *very* well in the long run.)

HTH,
--ag
 
M

Martin Ambuhl

sudip said:
the compiler is throwing the following error

in function 'main':
:undefined reference to 'sin'

...and stops the compilation process..
I'm stuck up, and can't figure out the error..plz help

The best help (teach a man to fish): check the FAQ before posting.

The inferior help (give you the fish): what you'll find there. Does it
look familiar?
<http://www.eskimo.com/~scs/C-faq/q14.3.html>
Question 14.3

I'm trying to do some simple trig, and I am #including <math.h>, but I
keep getting ``undefined: sin'' compilation errors.

Make sure you're actually linking with the math library. For instance,
under Unix, you usually need to use the -lm option, at the end of the
command line, when compiling/linking. See also questions 13.25 and 13.26.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top