g++ 3.2.X: undefined reference to `abs(int)'

Discussion in 'C++' started by Daniel Heiserer, Sep 23, 2003.

  1. hi,

    I am sure that is a stupid error of mine, but why the hell
    does this not work:
    -------------------------------------------
    >g++ test.cc

    /tmp/ccUN1Hel.o: In function `main':
    /tmp/ccUN1Hel.o(.text+0x26): undefined reference to `abs(int)'
    collect2: ld returned 1 exit status
    -------------------------------------------
    > cat test.cc

    #include <stdlib.h>
    #include <stdio.h>

    int main(){
    int abs(int);
    for (int jj=10;jj>=-10;jj--){
    fprintf(stdout,"%d ===> %d\n",jj,abs(jj));
    }
    return 0;
    }
    -------------------------------------------
    >man 3 abs

    ABS(3) Linux Programmer's
    Manual ABS(3)
    NAME
    abs, labs, llabs, imaxabs - compute the absolute value of an
    integer.
    SYNOPSIS
    #include <stdlib.h>

    int abs(int j);
    long int labs(long int j);
    long long int llabs(long long int j);
    -------------------------------------------
    thanks, daniel
     
    Daniel Heiserer, Sep 23, 2003
    #1
    1. Advertising

  2. Daniel Heiserer

    Attila Feher Guest

    Daniel Heiserer wrote:
    > hi,
    >
    > I am sure that is a stupid error of mine, but why the hell
    > does this not work:
    > -------------------------------------------
    >> g++ test.cc

    > /tmp/ccUN1Hel.o: In function `main':
    > /tmp/ccUN1Hel.o(.text+0x26): undefined reference to `abs(int)'
    > collect2: ld returned 1 exit status
    > -------------------------------------------
    >> cat test.cc

    > #include <stdlib.h>
    > #include <stdio.h>
    >
    > int main(){
    > int abs(int);


    You don't need the above line. <stdlib.h> declares abs so you must not do
    it.

    --
    Attila aka WW
     
    Attila Feher, Sep 23, 2003
    #2
    1. Advertising

  3. Daniel Heiserer

    Chris Dams Guest

    Daniel Heiserer <> writes:

    Hello,

    >#include <stdlib.h>
    >#include <stdio.h>


    Should nowadays be:

    #include <cstdlib>
    #include <cstdio>

    using namespace std;

    >int main(){
    > int abs(int);


    Remove this line, that will solve the error.

    > for (int jj=10;jj>=-10;jj--){
    > fprintf(stdout,"%d ===> %d\n",jj,abs(jj));
    > }
    > return 0;
    >}


    Bye,
    Chris Dams
     
    Chris Dams, Sep 23, 2003
    #3
    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. Schnoffos
    Replies:
    2
    Views:
    1,221
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,648
    Old Wolf
    Jan 20, 2004
  3. Klaas Vantournhout

    f2c's abs conflicts with <complex> abs

    Klaas Vantournhout, Oct 31, 2006, in forum: C++
    Replies:
    3
    Views:
    388
    Victor Bazarov
    Oct 31, 2006
  4. Replies:
    3
    Views:
    3,059
  5. Stefan Ram

    unsigned abs(int)?

    Stefan Ram, Jun 29, 2012, in forum: C Programming
    Replies:
    5
    Views:
    767
    Tim Rentsch
    Jul 2, 2012
Loading...

Share This Page