Post by Ulrich EckhardtGCC is the GNU Compiler Collection. With modern, I mean anything since
version 4 (though version 3 is also not completely out-of-date). I tested
my code with version 4.2 for Linux/x86.
Ok here's code:
***@linux:~/tmp$ uname -a
Linux linux 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18 18:40:08 UTC
2009 i686 GNU/Linux
***@linux:~/tmp$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
4.3.3-5ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.3/
README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/
usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-
included-gettext --enable-threads=posix --enable-nls --with-gxx-
include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-
clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --
enable-targets=all --with-tune=generic --enable-checking=release --
build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
***@linux:~/tmp$ cat pow1.c
#include <stdio.h>
#include <math.h>
int
main(void)
{
printf("%f\n", pow(2,3));
return 0;
}
***@linux:~/tmp$ gcc -o pow1 pow1.c
***@linux:~/tmp$ ./pow1
8.000000
***@linux:~/tmp$ cat pow3.c
#include <stdio.h>
#include <math.h>
int
main(void)
{
int x;
int y = 3;
for (x=2; x<11; x++)
printf("%f\n", pow(x,y));
return 0;
}
***@linux:~/tmp$ gcc -o pow3 pow3.c
/tmp/cciCYuL1.o: In function `main':
pow3.c:(.text+0x31): undefined reference to `pow'
collect2: ld returned 1 exit status
***@linux:~/tmp$ gcc -o pow3 pow3.c -lm
***@linux:~/tmp$ ./pow3
8.000000
27.000000
64.000000
125.000000
216.000000
343.000000
512.000000
729.000000
1000.000000
***@linux:~/tmp$
It is rather "modern GCC" since it is 4.3.3
Anyhow, it does not compile pow3.c program without math library linked
explicitly.
Program pow1.c is succesfully compiled because in fact it _does_not_
call pow at all.
Regards