undefined reference to `ceil' (or pow or floor or ...) in ubuntu 11.10

There has been a change to the build tools in ubuntu 11.10 - The "--as-needed" flag is now passed to the linker. This primarily has implications for dynamic library linking but it also affects the order that libraries appear on the command line even for static linking.

A simple example of the problem:

frankster@frankie-laptop:~> cat testm.c
#include <math.h>

int main(int argc, char*argv[]){
double x;
double return_val = ceil(x);
return 0;
}
frankster@frankie-laptop:~> gcc -lm testm.c
/tmp/ccNkQLo6.o: In function `main':
testm.c:(.text+0x15): undefined reference to `ceil'
collect2: ld returned 1 exit status>

A quick fix solution could be to pass the "-Wl,--no-as-needed" option to gcc which turns off the option in ld. However the real problem in the example I provided is the order of -lm and testm.c. The following builds successfully:

gcc testm.c -lm

More info at http://www.gentoo.org/proj/en/qa/asneeded.xml andhttps://wiki.ubuntu.com/OneiricOcelot/ReleaseNotes?action=show&redirect=OneiricOcelot%2FTechnicalOverview#GCC_4.6_Toolchain

你可能感兴趣的:(undefined reference to `ceil' (or pow or floor or ...) in ubuntu 11.10)