Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > <math.h> problem

Reply
Thread Tools

<math.h> problem

 
 
Ben Pfaff
Guest
Posts: n/a
 
      08-14-2003
"John B." <> writes:

> I'm self teaching myself C on a Linux box but I can't get a simple program
> to recognize math functions. I start the program with:


You forgot to read the FAQ.
--
"I am worth much more brick-bat!!"
--Uday Joshi
 
Reply With Quote
 
 
 
 
John B.
Guest
Posts: n/a
 
      08-14-2003
I'm self teaching myself C on a Linux box but I can't get a simple program
to recognize math functions. I start the program with:

#include <stdio.h>
#include <math.h> but when I compile the program, it does not
recognize sin(x); or pow(x,y) etc, in any equation.

/usr/include does have a math.h file. Any help or things to try would
be greatly appreciated!!!!. (I do alot of graphic things with trig.)
thanks







 
Reply With Quote
 
 
 
 
Tim Hagan
Guest
Posts: n/a
 
      08-14-2003
"John B." wrote:
>
> I'm self teaching myself C on a Linux box but I can't get a simple program
> to recognize math functions. I start the program with:
>
> #include <stdio.h>
> #include <math.h> but when I compile the program, it does not
> recognize sin(x); or pow(x,y) etc, in any equation.
>
> /usr/include does have a math.h file. Any help or things to try would
> be greatly appreciated!!!!. (I do alot of graphic things with trig.)
> thanks


It's a FAQ.

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

A: 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, 13.26, and 14.2.

See the rest at http://www.eskimo.com/~scs/C-faq/top.html

--
Tim Hagan
 
Reply With Quote
 
Derk Gwen
Guest
Posts: n/a
 
      08-14-2003
"John B." <> wrote:
# I'm self teaching myself C on a Linux box but I can't get a simple program
# to recognize math functions. I start the program with:
#
# #include <stdio.h>
# #include <math.h> but when I compile the program, it does not
# recognize sin(x); or pow(x,y) etc, in any equation.

It compiles but has link errors? On most platform, you have to link the math
library. On unices this is done with a -lm on the ld command (or *cc command
used to call ld).

--
Derk Gwen http://derkgwen.250free.com/html/index.html
GERBILS
GERBILS
GERBILS
 
Reply With Quote
 
Kevin Bracey
Guest
Posts: n/a
 
      08-19-2003
In message <>
Derk Gwen <> wrote:

> "John B." <> wrote:
> # I'm self teaching myself C on a Linux box but I can't get a simple
> # program to recognize math functions. I start the program with:
>
> It compiles but has link errors? On most platform, you have to link the
> math library. On unices this is done with a -lm on the ld command (or *cc
> command used to call ld).


I've never quite understood why this is. Presumably it has something to
do with reducing code size, but are Unix linkers not sophisticated enough to
omit unused portions of libraries automatically?

Surely a modern Unix C environment could default to including the whole ISO C
library and omit the portions not required?

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57