473,385 Members | 1,673 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,385 software developers and data experts.

<math.h> problem

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 j1**@yahoo.com



Nov 13 '05 #1
4 13361
"John B." <j1**@yahoo.com> 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
Nov 13 '05 #2
"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 j1**@yahoo.com


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
Nov 13 '05 #3
"John B." <j1**@yahoo.com> 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
Nov 13 '05 #4
In message <vj************@corp.supernews.com>
Derk Gwen <de******@HotPOP.com> wrote:
"John B." <j1**@yahoo.com> 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/
Nov 13 '05 #5

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

Similar topics

33
by: Darius Fatakia | last post by:
Hi, I seem to be having trouble with some of my math functions (pow, sqrt, acos). They're the only ones I use in my code and they prevent the program from compiling. I get a "undefined reference...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.