linux - g++ 静态链接到 libstdc++.a 错误

标签 linux gcc static-libraries static-linking g++-4.7

我的应用程序可以通过 CentOS 6.5 附带的 GCC/G++ 4.4.7 成功编译和链接。

我想通过 -static-libstdc++ 静态链接 libstdc++.a ,但 4.4.7 不支持它。 因此我通过以下命令安装了redhat-devtools-1.1,并将GCC/G++升级到4.7.2

cd /etc/yum.repos.d
wget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo 
yum --enablerepo=testing-1.1-devtools-6 install devtoolset-1.1-gcc devtoolset-1.1-gcc-c++

然后使用新工具集编译我的应用程序,但失败了

/opt/centos/devtoolset-1.1/root/usr/bin/c++ -m64   -c -O2 -Iinc -fPIC  -MMD -MP -MF "AutoInit.o.d" -o AutoInit.o AutoInit.cpp
/opt/centos/devtoolset-1.1/root/usr/bin/gcc   -m64   -c -O2 -D_LARGEFILE64_SOURCE=1 -Iinc -std=c99 -fPIC  -MMD -MP -MF "common.o.d" -o common.o common.c
/opt/centos/devtoolset-1.1/root/usr/bin/gcc   -m64   -c -O2 -D_LARGEFILE64_SOURCE=1 -Iinc -std=c99 -fPIC  -MMD -MP -MF "rpc.o.d" -o rpc.o rpc.c
/opt/centos/devtoolset-1.1/root/usr/bin/gcc   -m64   -c -O2 -D_LARGEFILE64_SOURCE=1 -Iinc -std=c99 -fPIC  -MMD -MP -MF "transport_service.o.d" -o transport_service.o transport_service.c
/opt/centos/devtoolset-1.1/root/usr/bin/gcc   -m64   -c -O2 -D_LARGEFILE64_SOURCE=1 -Iinc -std=c99 -fPIC  -MMD -MP -MF "interop.o.d" -o interop.o interop.c
/opt/centos/devtoolset-1.1/root/usr/bin/gcc   -m64   -c -O2 -D_LARGEFILE64_SOURCE=1 -Iinc -std=c99 -fPIC  -MMD -MP -MF "utility.o.d" -o utility.o utility.c
/opt/centos/devtoolset-1.1/root/usr/bin/g++ -o libmq.so AutoInit.o common.o rpc.o transport_service.o interop.o utility.o -L./lib -l:libapr-1.a -l:libcurl.a -l:libjansson.a -static-libgcc -static-libstdc++ -Wl,--start-group -l:libzmq.a -l:libczmq.a -Wl,--end-group -shared -fPIC
/usr/bin/ld: /opt/centos/devtoolset-1.1/root/usr/lib/gcc/x86_64-redhat-linux/4.7.2/libstdc++.a(compatibility.o): relocation R_X86_64_32 against `_ZTIN10__cxxabiv115__forced_unwindE' can not be used when making a shared object; recompile with -fPIC
/opt/centos/devtoolset-1.1/root/usr/lib/gcc/x86_64-redhat-linux/4.7.2/libstdc++.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status

请问您知道如何解决这个问题吗?

最佳答案

libstdc++.a 可能是在没有 -fPIC 的情况下编译的,因此 ld 禁止使用它构建共享对象。 http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/ 。可能您需要自己重新编译 libstdc++.a。

关于linux - g++ 静态链接到 libstdc++.a 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21593283/

相关文章:

tensorflow - 用 bazel 构建 tensorflow 不会产生静态库文件?

linux - 在 GNU/Linux 中,如何将 mingw-w64 与 SCons 结合使用来生成 64 位 Windows 可执行文件?

linux - 从用户空间捕获 Linux 中的挂起/恢复

linux - GIT 提交后,我做了 GIT 推送,但消息说一切都是最新的

c - 如何在使用 GCC 编译的 C 文件中指定输出部分?

c++ - 不明确的成员访问表达式 : is Clang rejecting valid code?

c - 多精度加法的意外表现

c++ - 如何使用静态库构建 Qt5 应用程序?

c++ - 静态库。导入和导出内联函数

linux - getpagesize() 与 sysconf(_SC_PAGESIZE)