静态链接glibc和boost_python36用于python扩展

时间:2018-08-24 06:53:59

标签: c++ boost-python

我正在为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

有人认识吗?谢谢。

1 个答案:

答案 0 :(得分:0)

原因可能是尽管存在libgcc,但它可能不在ldconfig已知的路径中。通过执行

进行检查
/sbin/ldconfig -p | grep libgcc

输出是否表明有指向libgcc的链接对应于上面列出的路径?

一种解决方法是,将指向相关库的链接添加到编译命令e.g.

中。
... -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。