Can't use pow() and sin()....

V

Victo

I tried to use pow() and sin().

but even I included <math.h>,
I can't use the 2 functions....

Why's that????

for example,


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

int main(void)
{
double a=2;
printf("%lf\n",sin(2));
return 1;
}


it returns the below error

Undefined first referenced
symbol in file
sin /var/tmp//ccJ0ckFm.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status


Why's that???
 
R

Ravi Uday

Victo said:
I tried to use pow() and sin().

but even I included <math.h>,
I can't use the 2 functions....

Why's that????

for example,


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

int main(void)
{
double a=2;
printf("%lf\n",sin(2));
return 1;
}


it returns the below error

Undefined first referenced
symbol in file
sin /var/tmp//ccJ0ckFm.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status


Why's that???

How are you compiling your file(s) ?

Have you seen FAQ: 14.3 ?

http://www.eskimo.com/~scs/C-faq/top.html

- Ravi
 
J

jacob navia

Victo said:
I tried to use pow() and sin().

but even I included <math.h>,
I can't use the 2 functions....

Why's that????

for example,


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

int main(void)
{
double a=2;
printf("%lf\n",sin(2));
return 1;
}


it returns the below error

Undefined first referenced
symbol in file
sin /var/tmp//ccJ0ckFm.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status


Why's that???

Open Letter to the gcc team:

Dear Sirs:

Regularly in comp.lang.c we get questions like
Can't use pow() and sin()

Could you INCLUDE the math library BY DEFAULT?????

Most compilers in the world spare their users this. The
math library will be included, sometimes together with
other libraries.

Rationale:

The standard language specifies sin/cos/pow etc. Since
those functions are part of the *standard* there is NO
reason to separate them from the C library. The distinction
is completely artificial.

Users do not have to include the C library. Why should
they include the math library?

Yours sincerely
 
M

Mark McIntyre

Most compilers in the world spare their users this. The
math library will be included, sometimes together with
other libraries.

I'm mostly with you on this, there's no reason (any longer) to have
the math component of the standard library unincluded by default,
but...
Rationale:

The standard language specifies sin/cos/pow etc. Since
those functions are part of the *standard* there is NO
reason to separate them from the C library.

.... remember that the Standard Library is NOT part of the gcc
compiler.
The distinction is completely artificial.

agreed. However I believe the gcc guys chose to implement a compiler,
and leave the standard library to the experts.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top