can not figure out the problem

Y

yezi

HI, ALL:

I can not figure out the problem with compiling.

the message is "
/tmp/ccAxyQSj.o(.text+0x275): In function `main':
: undefined reference to `sqrt'
collect2: ld returned 1 exit status
"

At first I thought is because the gcc "math.h" do not have the function
: then I type "gcc --version "

gcc (GCC) 3.3.2 20031022 (Red Hat Linux 3.3.2-1)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

Then I use "man sqrt " in my system, it works.

My question : why the compiler failure?

THanks


bin YE
 
D

David Resnick

yezi said:
HI, ALL:

I can not figure out the problem with compiling.

the message is "
/tmp/ccAxyQSj.o(.text+0x275): In function `main':
: undefined reference to `sqrt'
collect2: ld returned 1 exit status
"

At first I thought is because the gcc "math.h" do not have the function
: then I type "gcc --version "

gcc (GCC) 3.3.2 20031022 (Red Hat Linux 3.3.2-1)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

Then I use "man sqrt " in my system, it works.

My question : why the compiler failure?

THanks


bin YE

http://www.eskimo.com/~scs/C-faq/q14.3.html

-David
 
F

Flash Gordon

yezi said:
HI, ALL:

I can not figure out the problem with compiling.

the message is "
/tmp/ccAxyQSj.o(.text+0x275): In function `main':
: undefined reference to `sqrt'
collect2: ld returned 1 exit status
"

At first I thought is because the gcc "math.h" do not have the function

<snip>

http://www.eskimo.com/~scs/C-faq/q14.3.html

I suggest you read the rest of the FAQ and the manuals for your compiler
& linker as well.
 
B

Barry Schwarz

HI, ALL:

I can not figure out the problem with compiling.

the message is "
/tmp/ccAxyQSj.o(.text+0x275): In function `main':
: undefined reference to `sqrt'
collect2: ld returned 1 exit status
"

It is not a compiler failure. It is a linker failure. You need to
look at your documentation to determine how to tell the linker it
should use the math library to resolve function references.
At first I thought is because the gcc "math.h" do not have the function

math.h is a header, not a library.
: then I type "gcc --version "

gcc (GCC) 3.3.2 20031022 (Red Hat Linux 3.3.2-1)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

Then I use "man sqrt " in my system, it works.

My question : why the compiler failure?

THanks


bin YE


<<Remove the del for email>>
 
M

manu

one reason could be you didnot use the -lm clause while compiling.
try that if you haven't used that
gcc -lm <file.c>

this should solve your problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top