Name: Anonymous 2013-05-14 13:45
Sup /prog/oyim. I'm having trouble linking a binary. Apparently the order of arguments has something to do with it. My Makefile instruction expands to this:
cc -lm -o myprog myprog.o libmylib.a
This works fine with the following compilers:
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
gcc version 4.2.1 20070831 patched [FreeBSD]
However, gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) gives the follow
myprog.o: In function `p_expt':
myprog.c:(.text+0x4670): undefined reference to `pow'
myprog.o: In function `p_sqrt':
myprog.c:(.text+0x46e7): undefined reference to `sqrt'
myprog.o: In function `p_atan':
myprog.c:(.text+0x478c): undefined reference to `atan2'
myprog.c:(.text+0x47a8): undefined reference to `atan'
myprog.o: In function `p_acos':
myprog.c:(.text+0x4817): undefined reference to `acos'
myprog.o: In function `p_asin':
myprog.c:(.text+0x4887): undefined reference to `asin'
myprog.o: In function `p_tan':
myprog.c:(.text+0x48f7): undefined reference to `tan'
myprog.o: In function `p_cos':
myprog.c:(.text+0x4967): undefined reference to `cos'
myprog.o: In function `p_sin':
myprog.c:(.text+0x49d7): undefined reference to `sin'
myprog.o: In function `p_log':
myprog.c:(.text+0x4a47): undefined reference to `log'
myprog.o: In function `p_exp':
myprog.c:(.text+0x4ab7): undefined reference to `exp'
myprog.o: In function `p_round':
myprog.c:(.text+0x4b2d): undefined reference to `floor'
myprog.o: In function `p_floor':
myprog.c:(.text+0x4b97): undefined reference to `floor'
myprog.o: In function `p_truncate':
myprog.c:(.text+0x4c0d): undefined reference to `ceil'
myprog.o: In function `p_ceiling':
myprog.c:(.text+0x4c77): undefined reference to `ceil'
collect2: ld returned 1 exit status
make: *** [myprog] Error
And Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn) compiles, but running gives me a segfault.
I managed to make it work on all platforms by moving my LDFLAGS to the end of the linker command.
cc -o myprog myprog.o libmylib.a -lm
My question is why does having the -lm flag first cause shit to go haywire?
cc -lm -o myprog myprog.o libmylib.a
This works fine with the following compilers:
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
gcc version 4.2.1 20070831 patched [FreeBSD]
However, gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) gives the follow
myprog.o: In function `p_expt':
myprog.c:(.text+0x4670): undefined reference to `pow'
myprog.o: In function `p_sqrt':
myprog.c:(.text+0x46e7): undefined reference to `sqrt'
myprog.o: In function `p_atan':
myprog.c:(.text+0x478c): undefined reference to `atan2'
myprog.c:(.text+0x47a8): undefined reference to `atan'
myprog.o: In function `p_acos':
myprog.c:(.text+0x4817): undefined reference to `acos'
myprog.o: In function `p_asin':
myprog.c:(.text+0x4887): undefined reference to `asin'
myprog.o: In function `p_tan':
myprog.c:(.text+0x48f7): undefined reference to `tan'
myprog.o: In function `p_cos':
myprog.c:(.text+0x4967): undefined reference to `cos'
myprog.o: In function `p_sin':
myprog.c:(.text+0x49d7): undefined reference to `sin'
myprog.o: In function `p_log':
myprog.c:(.text+0x4a47): undefined reference to `log'
myprog.o: In function `p_exp':
myprog.c:(.text+0x4ab7): undefined reference to `exp'
myprog.o: In function `p_round':
myprog.c:(.text+0x4b2d): undefined reference to `floor'
myprog.o: In function `p_floor':
myprog.c:(.text+0x4b97): undefined reference to `floor'
myprog.o: In function `p_truncate':
myprog.c:(.text+0x4c0d): undefined reference to `ceil'
myprog.o: In function `p_ceiling':
myprog.c:(.text+0x4c77): undefined reference to `ceil'
collect2: ld returned 1 exit status
make: *** [myprog] Error
And Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn) compiles, but running gives me a segfault.
I managed to make it work on all platforms by moving my LDFLAGS to the end of the linker command.
cc -o myprog myprog.o libmylib.a -lm
My question is why does having the -lm flag first cause shit to go haywire?