如何让ld使用libc.a的PIC版本
How to let ld use PIC version of libc.a
将linkgcc静态成共享库,根据this question中的答案,剩下的问题就是如何让linker使用PIC版本的libc.a 而不是非 PIC 版本。问题与答案相同:
g++ -fPIC -Wall -O0 -fexceptions -g -c main.cpp -o main.o
ld -shared -static -o test.so main.o -lc
ld: //usr/lib/x86_64-linux-gnu/libc.a(malloc.o): relocation R_X86_64_TPOFF32 against `tcache' can not be used when making a shared object; recompile with -fPIC
这是我试过的:
sudo apt-get install libc-pic //then libc6-pic get installed successfully
ld -shared -static -o test.so main.o -lc //same as above, same error
ld -shared -static -o test.so main.o -lc-pic //not working: cannot find -lc-pic
ld -shared -static -o test.so main.o -lc6-pic //not working: cannot find -lc6-pic
查看 the list of files in the package 有一个 libc_pic.a
所以正确的选项似乎是 -lc_pic
。
将linkgcc静态成共享库,根据this question中的答案,剩下的问题就是如何让linker使用PIC版本的libc.a 而不是非 PIC 版本。问题与答案相同:
g++ -fPIC -Wall -O0 -fexceptions -g -c main.cpp -o main.o
ld -shared -static -o test.so main.o -lc
ld: //usr/lib/x86_64-linux-gnu/libc.a(malloc.o): relocation R_X86_64_TPOFF32 against `tcache' can not be used when making a shared object; recompile with -fPIC
这是我试过的:
sudo apt-get install libc-pic //then libc6-pic get installed successfully
ld -shared -static -o test.so main.o -lc //same as above, same error
ld -shared -static -o test.so main.o -lc-pic //not working: cannot find -lc-pic
ld -shared -static -o test.so main.o -lc6-pic //not working: cannot find -lc6-pic
查看 the list of files in the package 有一个 libc_pic.a
所以正确的选项似乎是 -lc_pic
。