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 and

By ff

Systems software engineer with interests in C/C++/Rust on Linux, electronic music and games.

7 replies on “undefined reference to `ceil' (or pow or floor or ...) in ubuntu 11.10”

Thanks a lot
I was in trouble for two days with ubuntu 11.10 and openembedded stable/2009 branch
this hint helped me to fix it by changing:
-Dldflags="${LDFLAGS}" \
-Dldflags="${LDFLAGS} -Wl,--no-as-needed -lpthread -lm" \
I hope it helps someone just like this article helped me

Hi I would like to update the operating system for my E-MU Virtuoso 2000 which is currently version 1.24 I believe there is an update to version 2.26?
My computer : Mac Pro 12 core
Mac OSX 10.9.5
I would also want to purchase either NEW,SECOND HAND or B stock from plastic silver front panel.
Many thanks

Leave a Reply

Your email address will not be published. Required fields are marked *