LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-03-2006, 04:11 PM   #1
manolakis
Member
 
Registered: Nov 2006
Distribution: xubuntu
Posts: 464

Rep: Reputation: 37
pow() problem in C


Hey there
I would be obliged if anyone could solve my problem
I have compiled 'myprogram.c' without errors by using 'gcc -c myprogram.c'
Well, when i am trying to link the object code to the executable by using gcc -o myprogram myprogram.o i get the following error:

myprogram.o(.text+0x6f3): In function `fuction1':
: undefined reference to `pow'

The fact is that i have tried to make another program without including <math.h>
and using pow().And finally It worked.
By the way, I am using Slackware Linux(BackTrack) if that matters.

Any ideas?
Thanks for your time.
 
Old 12-03-2006, 04:21 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
pass -lm to link in the math library.
 
Old 12-03-2006, 04:35 PM   #3
manolakis
Member
 
Registered: Nov 2006
Distribution: xubuntu
Posts: 464

Original Poster
Rep: Reputation: 37
Hey again
I am really sorry but i am quite newbie
Could you illustrate me how to do it?
 
Old 12-03-2006, 06:20 PM   #4
king111
Member
 
Registered: Jul 2005
Distribution: Debian, Ubuntu
Posts: 85

Rep: Reputation: 15
Code:
cc myprogram.c -o myprogram -lm
 
Old 12-03-2006, 06:44 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
When you link a program using gcc, you specify what libraries to link into your target using the -l switch. gcc will look in common directories for libraries. If you say "-lm" gcc will search for "libm.so" or "libm.a" (depending on other options). libm is the math library, where pow() is defined.
 
Old 12-04-2006, 06:25 PM   #6
manolakis
Member
 
Registered: Nov 2006
Distribution: xubuntu
Posts: 464

Original Poster
Rep: Reputation: 37
Many thanks for your help
It was really nice of you
 
  


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
Simple C pow() program, strange error funkymunky Programming 2 06-25-2004 04:20 AM
Linux: Problems with pow() from /usr/include/tgmath.h jimmy416 Programming 1 10-13-2003 05:43 PM
C programming: pow(0,0) = 1 ? Should be undefined. the theorist Programming 10 04-08-2003 06:29 PM
POW, what does it mean to you? Edward78 General 7 08-20-2002 08:10 AM
pow in c acid_kewpie Programming 3 11-12-2001 06:11 PM

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

All times are GMT -5. The time now is 10:01 AM.

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