首页 > 解决方案 > python 扩展的静态链接 glibc & boost_python36

问题描述

我正在为 pyton3.6 编写扩展。我的开发机运行gcc7.3,生产环境os是centos6。我使用以下链接选项静态链接 glibc 以避免将 glibc2.12 升级到 glibc2.14+。

-Wl,-Bdynamic -lpython3.6m -Wl,-Bstatic -lboost_python36

但得到错误:

[ 50%] Linking CXX shared module helloext.so
/usr/bin/x86_64-linux-gnu-ld: cannot find -lgcc_s
/usr/bin/x86_64-linux-gnu-ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
CMakeFiles/helloext.dir/build.make:94: recipe for target 'helloext.so' failed
make[2]: *** [helloext.so] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/helloext.dir/all' failed
make[1]: *** [CMakeFiles/helloext.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

有人知道吗?谢谢。

标签: c++boost-python

解决方案


原因可能是尽管存在 libgcc,但它可能不在ldconfig已知的路径中。通过做检查这个

/sbin/ldconfig -p | grep libgcc

输出是否显示有一个指向 libgcc 的链接对应于您上面列出的路径?

一种解决方法可能是将相关库的链接添加到您的编译命令中,例如

... -L /usr/lib/gcc/x86_64-linux-gnu/4.6/

另一个可能是自己创建一个到库的符号链接。

 ln -s /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so /usr/lib/gcc/libgcc_s.so

您尚未告知我们您正在使用的 Linux。在上面的命令中使用正确的数字更新 4.6。


推荐阅读