LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2006, 06:28 PM   #1
anon192
LQ Newbie
 
Registered: Mar 2006
Location: Portola CA
Distribution: Kubuntu Drapper Drake
Posts: 3

Rep: Reputation: 0
math library issues on ubuntu 5.10 (i think)


it seems that any program that i try to compile (using gcc) that needs the math.h library doesnt have the required functions.

when i use the following program: (sorry i dont know how to put it in the boxes and im in a hurry)
#include <stdio.h>
#include <math.h>

int main()
{
float s1=sin(M_PI/2);
float s2=cos(M_PI/2);
float s3=tan(M_PI/2);
return 1;
}


i get: (again, sry)
/tmp/ccia1gtc.o: In function `main':
test.c.text+0x2c): undefined reference to `sin'
test.c.text+0x46): undefined reference to `cos'
test.c.text+0x60): undefined reference to `tan'
collect2: ld returned 1 exit status

any suggestions?
 
Old 06-13-2006, 06:53 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Are you compiling with the "-lm" flag?
 
Old 06-14-2006, 12:33 AM   #3
anon192
LQ Newbie
 
Registered: Mar 2006
Location: Portola CA
Distribution: Kubuntu Drapper Drake
Posts: 3

Original Poster
Rep: Reputation: 0
no, i wasnt. that made it all work. thank you so much. what does the lm flag do, tho?
 
Old 05-04-2007, 01:36 PM   #4
ramowl
Member
 
Registered: Jun 2003
Location: NM
Distribution: Suse 10.1
Posts: 56

Rep: Reputation: 15
Question Need A "How To" On Using "lm"!

I am trying to brush up on my C++ programming that I learned in school. I'm using Ubuntu (Edgy) on a laptop as my learning tool.

My programs uses the following form:

//practice.cpp
#include <iostream>
#include <math>
using namespace std;

int main ()
{
float numberInput = (float) 0.0;
float square = (float) 0.0;
float sqRoot = (float) 0.0;

cout << "Enter a number: ";
cin >> numberInput;

square = (float) pow(numberInput, 2);
sqRoot = (float) sqrt(numberInput);

cout << "Square of << numberInput << " = " << square << endl;
cout << "Square Root of " << numberInput << " = " << sqrt << end;

return 0;
}

When I do a "locate math.h" in my terminal window, it shows me:

/usr/include/math.h


I tried: g++ -o practice -lm math.h practice.cpp
That did'nt work!

I tried: g++ -o practice -lm /user/include/math.h practice.cpp
That did'nt work!

Assuming the /usr/include/math.h file is the correct one, what is the correct syntax for linking the math library to the compiler?

I tried googling for it, but had no luck so far.
 
  


Reply



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 program that I can enter math functions ... Four General 5 04-19-2006 08:02 PM
ANSI C: Math library making #include unnecessary? olspookishmagus Programming 3 11-01-2005 09:50 AM
math library for linux kooshball Programming 4 05-28-2005 07:05 PM
Esetroot, Eterm, and other library issues libranikki Fedora 1 07-06-2004 06:31 AM
Issues with Aspell, it's library, and Gaim kko88 Linux - Software 2 05-17-2003 01:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:51 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
Open Source Consulting | Domain Registration