473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

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???
Nov 14 '05 #1
6 3323
On Mon, 28 Mar 2005 21:18:40 +0800, Victo wrote:
I tried to use pow() and sin().

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

Why's that????


Link with -lm

Greetings,
Steffen.
Nov 14 '05 #2
Victo wrote:
I tried to use pow() and sin().

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

Why's that????


This is Question 14.3 in the comp.lang.c Frequently
Asked Questions (FAQ) list

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

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 14 '05 #3


Victo wrote:
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

Nov 14 '05 #4
gcc foo.c -o foo.o -lm

Nov 14 '05 #5
Victo wrote:
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

Nov 14 '05 #6
On Mon, 28 Mar 2005 23:28:27 +0200, in comp.lang.c , jacob navia
<ja***@jacob.remcomp.fr> wrote:
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.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: franky.backeljauw | last post by:
Hello, I have the following code: <code> class X { ___ sin(); } X sin( X ) { return sin( y, x ); }
14
by: Alexander Stippler | last post by:
Hi, simple question. Why does this not work: #include <algorithm> #include <cmath> #include <iostream> int main()
5
by: Magix | last post by:
#include <math.h> double pow( double base, double exp ); will pow (2, -30) works fine ? (exp is negative value). If not, what are the workaround for exp to be negative?
15
by: Mark Healey | last post by:
I'm using gcc on a fedora 3 system here are what I think the relevant lines are: #include <math.h> r=pow(2,z); When I compile I get
1
by: jeniffer | last post by:
This is a C program compiled on gcc compiler that tries to set a new entry in the arp cache,get an entry and also delete an entry from it.I have run this program but in the set function Set_Entry...
42
by: John Smith | last post by:
In a C program I need to do exponentiation where the base is negative and the exponent is a fraction. In standard C this would be something like t = pow(-11.5, .333), but with this combination of...
8
by: Chris Stankevitz | last post by:
Q1: Does c++ provide pow(int,int)? Q2: If not, why not? Thanks, Chris
13
by: siggi | last post by:
Hi all, this is a newbie question on : Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32 PC with WinXP In http://www.python.org/doc/2.3.5/lib/module-math.html I read:
18
by: Peng Yu | last post by:
Hi, I'm wondering if there is any general guideline on when to using something like std::pow(x, n) rather than x * x * x * ... * x (n x's). Thanks, Peng
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.