【问题标题】:g++ static link to libstdc++.a errorg++ 静态链接到 libstdc++.a 错误
【发布时间】:2014-02-06 03:15:28
【问题描述】:

我的应用程序可以通过 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

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

【问题讨论】:

  • 我在 4.7 中遇到了这个问题
  • 没关系,我现在看到你把“升级”了。

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


【解决方案1】:

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

【讨论】:

  • 是的,我想是的,但是有什么办法可以避免重新编译 stdc++?
猜你喜欢
  • 1970-01-01
  • 2023-03-24
  • 2013-06-17
  • 1970-01-01
  • 2014-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-30
相关资源
最近更新 更多