LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-26-2008, 10:29 AM   #1
Bethmo
LQ Newbie
 
Registered: Feb 2008
Posts: 5

Rep: Reputation: 0
math.h doesn't seem to be working


Hello!
I am a new user of linux(although with a 4 year old distribution of Mandrake), and have a very small amount of c programming. Anyway I believe the function "sin" is part of math.h, but when I use the function gcc claims to not have heard of it. Similar for other math.h functions. So: Is there a problem with my math.h? Can I get a new one? Or am I just a deluded fool and sin shouldn't be in this header file at all?
 
Old 02-26-2008, 10:34 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
if you include math.h you need to link in libm.a with the -lm option, vis:

gcc myprog.c -o myprog -lm
 
Old 02-26-2008, 10:35 AM   #3
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
If I remember it right, you have to use the command line switch '-lm' when including math.h.
Code:
gcc -lm yourcode.c
 
Old 02-26-2008, 01:05 PM   #4
Bethmo
LQ Newbie
 
Registered: Feb 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Thats absolutely brilliant.

Err...do I have to do this with any other header files? Also why do I have to? Is there some kind of internetland place I can go to to read this?
 
Old 02-26-2008, 01:22 PM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
You have to do this when the function is not in the standard library; that's however not for every include file the case (e.g functions in stdio.h do not need an additional to be linked).

Unfortunately I can not tell you where to find the info.

PS
Just in case you want to ask more programming related questions in the future:
there is a dedicated programming section at LQ that's better suited for programming related questions.

Last edited by Wim Sturkenboom; 02-26-2008 at 01:25 PM. Reason: added PS
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
math.h Damicles Programming 9 12-04-2010 06:51 AM
Numpad math keys not working in ADOM? AlucardZero Linux - Software 1 10-18-2007 02:22 PM
math program that I can enter math functions ... Four General 5 04-19-2006 09:02 PM
Problem with math.h loke137 Programming 4 02-12-2004 08:12 AM
python2.3 - import math module not working dumpthecore Programming 2 12-10-2003 11:30 PM


All times are GMT -5. The time now is 04:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration