468,780 Members | 2,264 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,780 developers. It's quick & easy.

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

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
Jul 19 '05 #1
2 6843
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
Jul 19 '05 #2
Daniel Heiserer <Da*************@bmw.de> 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
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by sandwich_eater | last post: by
33 posts views Thread by Evangelista Sami | last post: by
14 posts views Thread by yang__lee | last post: by
3 posts views Thread by Michael | last post: by
13 posts views Thread by John Doe | last post: by
15 posts views Thread by arnuld | last post: by
10 posts views Thread by Robert Dailey | last post: by
41 posts views Thread by Summercool | last post: by
1 post views Thread by CARIGAR | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.