静态libgcc中我有问题的链接libgcc中为静态链接。所以为什么不能链接64位Ubuntu上
与-m64
64位的Ubuntu 12.10 gcc的64位链接模块时4.7
也未能它只发生在Ubuntu 64位12.04 GCC 4.6
32位没有问题
$gcc -fPIC -c -o hello.o hello.c -m32
$gcc -shared -m32 hello.o -o libhello.so -static-libgcc -Wl,-Bstatic -lc
$ ldd libhello.so
statically linked
64位失败
$ make
gcc -fPIC -c -o hello.o hello.c
gcc -shared -m64 hello.o -o libhello.so -static-libgcc -Wl,-Bstatic -lc
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libc.a(iofclose.o): relocation R_X86_64_32 against `__gcc_personality_v0' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libc.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [libhello.so] Error 1
的hello.c
#include <stdio.h>
int f(){
FILE *out = fopen("/tmp/x.log", "wb");
fclose(out);
return 1;
}
的Makefile
all: libhello.so
libhello.so: hello.o
gcc -shared -m64 hello.o -o libhello.so -static-libgcc -Wl,-Bstatic -lc
hello.o: hello.c
gcc -fPIC -c -o hello.o hello.c
clean:
rm -f hello.o libhello.so
根据[本文](http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3),这意味着“libc.a”不是使用-fPIC编译,但必须在-fPIC库中静态链接。 – BeniBela 2013-02-25 17:51:01
如果您在64位机器上编译,难道您不能省略-m64标志吗?这会有帮助吗? – 2013-02-26 21:27:31
@RandallCook同样的错误 – farmer1992 2013-02-27 02:11:30