[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

GCC undefined reference

Posted on 1999-12-21
11
Medium Priority
?
915 Views
Last Modified: 2012-08-13

I've ran into a snag learning the C
language and am unsure how to
proceed. Today, when I tried to
compile a program with the pow
function, the following output
(Linux 6.1) was displayed in a
Konsole:

gcc prob4_3.c
/tmp/ccNFcbg2.o: In function 'main':
/tmp/ccNFcbg2.o(.text+0x103): undefined reference to 'pow'
collect2: ld returned 1 exit status

I'm guessing 1 exit status is the
blanket response for undefined
references but the file references
are beyond my knowledge+time right now.
Thx. burritoboy
 
0
Comment
Question by:burritoboy
  • 4
  • 4
  • 2
  • +1
11 Comments
 

Expert Comment

by:Dunbuje
ID: 2299681
Please show us your source code inorder for us to help you .
0
 
LVL 10

Expert Comment

by:rbr
ID: 2300155
to burritoboy:

Add the -lm flag to your compiler command.

to Dunbuje: Don't lock a question, if you give no answer.
0
 
LVL 10

Expert Comment

by:rbr
ID: 2300156
to Dunbuje: You say you are an expert in unix and C and you don't know an answer to this simple problem.
0
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 

Author Comment

by:burritoboy
ID: 2300526
Dear Sir or Madam:
I appreciate your effort, but
rbr is right on. rbr gets the
points if he/she tells me
what this option meant exactly...
so I can look it up for myself
on similar questions.

-l  library (I think?)
not sure of the "m" in "-lm"
 
--burritoboy
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2300590
math library(libm.a)?

-llibrary

Search the library named library when linking.

It makes a difference where in the command you write this option; the linker searches processes libraries and object files in the order they are specified.  Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o.  If bar.o refers to functions in z, those functions may not be loaded.

The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a.  The linker then uses this file as if it had been specified precisely by name.

The directories searched include several standard system directories plus any that you specify with -L.

Normally the files found this way are library files--archive files whose members are object files.  The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined.  But if the file that is found is an ordinary object file, it is linked in the usual fashion.  The only difference between using an -l option and specifying a file name is that -l surrounds library with lib and .a and searches several directories.

0
 
LVL 10

Accepted Solution

by:
rbr earned 210 total points
ID: 2301153
-lm
-l stands for libray
m is the mathematical library where all those function are in it. (sin, cos, pow, ...)

-lm search for the library libm.a in the standard library direcory (i.g. /usr/lib)
0
 

Expert Comment

by:Dunbuje
ID: 2302037
To rbr, i am sorry for misunderstanding . I am not that expert in Unix and C but still learning. I am using Solaris on SPARC 10 Sun Workstation machine developing my programs in C language in Visual C++ compiler as well as Borland C++ on PC.
I thought that burritoboy was asking some problems he faced for a program he made so I asked him to show the code he was compilingb so that we can help. My one sentence above was not meant to answer the question but to ask him to provide the C language code he was compiling.
I am new to this group discussions so, if locked the question it was a mistake but it was intenional any way since i am new to this forum.
Let's not be rude to each other but work together.!

   
0
 

Expert Comment

by:Dunbuje
ID: 2302041
To rbr, i am sorry for misunderstanding . I am not that expert in Unix and C but still learning. I am using Solaris on SPARC 10 Sun Workstation machine developing my programs in C language in Visual C++ compiler as well as Borland C++ on PC.
I thought that burritoboy was asking some problems he faced for a program he made so I asked him to show the code he was compilingb so that we can help. My one sentence above was not meant to answer the question but to ask him to provide the C language code he was compiling.
I am new to this group discussions so, if locked the question it was a mistake but it was not intenional any way since i am new to this forum.
Let's not be rude to each other but work together.!

   
0
 

Expert Comment

by:Dunbuje
ID: 2302054
To rbr, i am sorry for misunderstanding . I am not that expert in Unix and C but still learning. I am using Solaris on SPARC 10 Sun Workstation machine developing my programs in C language in Visual C++ compiler as well as Borland C++ on PC.
I thought that burritoboy was asking some problems he faced for a program he made so I asked him to show the code he was compilingb so that we can help. My one sentence above was not meant to answer the question but to ask him to provide the C language code he was compiling.
I am new to this group discussions so, if locked the question it was a mistake but it was not intenional any way since i am new to this forum.
Let's not be rude to each other but work together.!  Please ignor the above message.

   
0
 

Author Comment

by:burritoboy
ID: 2302171
Thx for the nuances KangaRoo and the
help rbr.

burritoboy

p.s. Dunbuje...don't feel bad
as I've been on UNIX machines for
about 5 yrs and am still learning.

0
 
LVL 10

Expert Comment

by:rbr
ID: 2303478
To Dunbuje: I didn't want to make you angry but I loose already a few thousand points for giving the right comment to wrong answer when the questioner didn't reject the wrong answer. Sorry!

P.S.: In your profile you claim that you be an expert ;->
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question