Link to home
Start Free TrialLog in
Avatar of burritoboy
burritoboy

asked on

GCC undefined reference


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
 
Avatar of Dunbuje
Dunbuje

Please show us your source code inorder for us to help you .
to burritoboy:

Add the -lm flag to your compiler command.

to Dunbuje: Don't lock a question, if you give no answer.
to Dunbuje: You say you are an expert in unix and C and you don't know an answer to this simple problem.
Avatar of burritoboy

ASKER

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
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.

ASKER CERTIFIED SOLUTION
Avatar of rbr
rbr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.!

   
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.!

   
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.

   
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.

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 ;->