g ++到libstdc ++的静态链接。一个错误

时间:2014-02-06 03:15:29

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

我的应用程序可以编译&通过GOS / G ++ 4.4.7成功链接,该版本随CentOS 6.5一起提供。

我想通过-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

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

1 个答案:

答案 0 :(得分:2)

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