I can ssh to my schools Ubuntu 11.04 server where I have to submit my code and this links fine:
ME@SCHOOL:~/309/project2$ make
gcc -lm treesort.c -o treesort
ME@SCHOOL:~/309/project2$
My local machine is running Ubuntu 12.04 and here is the compiler output for the same code, but using the NetBeans makefile:
gcc -lm -o dist/Release/GNU-Linux-x86/treesort build/Release/GNU-Linux-x86/sortFns.o build/Release/GNU-Linux-x86/treesort.o
build/Release/GNU-Linux-x86/treesort.o: In function `processargs':
treesort.c:(.text+0x144): undefined reference to `log'
collect2: ld returned 1 exit status
Using the command line on my local machine with the same code and makefile from the first example:
ME@MYCOMPUTER:~/Documents/CSCI/309/project2$ make
gcc -lm treesort.c -o treesort
/tmp/ccY5GqF1.o: In function `processargs':
treesort.c:(.text+0x2b5): undefined reference to `log'
collect2: ld returned 1 exit status
make: *** [all] Error 1
ME@MYCOMPUTER:~/Documents/CSCI/309/project2$
This is really quite irritating, and I can’t figure out why it works on the server and not on my local machine. I found this question, but it didn’t help.
Put
-lmat the end of the link line. The order of sources,objects and (archive) libraries on the link line matters, and yours is wrong.If putting
-lmat the end of the link line doesn’t help, you have some bogus library calledlibm.{a,so}somewhere on your system, and you should figure out where it came from, and get rid of it.You cam find out which
libmyour linker is finding withgcc -Wl,-t ...