• C

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
 
burritoboyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Add the -lm flag to your compiler command.

to Dunbuje: Don't lock a question, if you give no answer.
0
rbrCommented:
to Dunbuje: You say you are an expert in unix and C and you don't know an answer to this simple problem.
0
Become a Leader in Data Analytics

Gain the power to turn raw data into better business decisions and outcomes in your industry. Transform your career future by earning your MS in Data Analytics. WGU’s MSDA program curriculum features IT certifications from Oracle and SAS.  

burritoboyAuthor Commented:
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
KangaRooCommented:
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
rbrCommented:
-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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DunbujeCommented:
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
DunbujeCommented:
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
DunbujeCommented:
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
burritoboyAuthor Commented:
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
rbrCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.