我有一个共享库,由我无法控制的另一个应用程序使用,它需要 *.so 对象。我的库使用了需要与其静态链接的 sqlite3(我绝对需要一个自包含的二进制文件)。
当我尝试编译和链接我的库时:
-fpic -flto -pthread -m64
-flto -static -shared
我最终得到以下错误:
/usr/bin/ld: /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/crtbeginT.o: relocation R_X86_64_32 against `__DTOR_END__' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/crtbeginT.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
使用 -fPIC 重新编译与什么有关?我的代码还是 CRT?
我已经尝试使用 -fPIC 编译我的对象,结果相同。
谢谢。
编辑:
该问题似乎与 SQLite3 无关。
我写了一个简单的单行无操作库,它编译和链接如下:
g++ -c -fPIC -o bar.o bar.cpp
g++ -shared -o bar.so bar.o
但不是这样:
g++ -c -fPIC -o bar.o bar.cpp
g++ -static -shared -o bar.so bar.o
该问题似乎与 CRT (crtbeginT.o) 有关。我应该重新编译 GCC --with-pic 还是什么?