can not figure out the problem

Discussion in 'C Programming' started by yezi, Nov 28, 2005.

  1. yezi

    yezi Guest

    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
     
    yezi, Nov 28, 2005
    #1
    1. Advertising

  2. yezi wrote:
    > 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
     
    David Resnick, Nov 28, 2005
    #2
    1. Advertising

  3. yezi

    yezi Guest

    many thanks , quite right~
     
    yezi, Nov 28, 2005
    #3
  4. yezi

    Flash Gordon Guest

    yezi wrote:
    > 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.
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, Nov 28, 2005
    #4
  5. On 28 Nov 2005 13:45:32 -0800, "yezi" <> wrote:

    >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>>
     
    Barry Schwarz, Nov 29, 2005
    #5
  6. yezi

    manu Guest

    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.
     
    manu, Nov 29, 2005
    #6
  7. "manu" <> writes:
    > one reason could be you didnot use the -lm clause while compiling.
    > try that if you haven't used that
    > gcc -lm <file.c>


    One reason for what?

    Please read <http://cfaj.freeshell.org/google/>.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Nov 29, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. logia
    Replies:
    6
    Views:
    656
  2. Steve
    Replies:
    0
    Views:
    535
    Steve
    Sep 25, 2006
  3. Gabriel Genellina
    Replies:
    2
    Views:
    268
    Miles
    Sep 25, 2007
  4. Albert Hopkins
    Replies:
    3
    Views:
    474
    Steven D'Aprano
    Dec 10, 2008
  5. J Snaith
    Replies:
    7
    Views:
    426
    J Snaith
    Apr 6, 2010
Loading...

Share This Page