静态链接 glibc & boost_python36 for Python extension

static link glibc & boost_python36 for python extension

本文关键字:python36 for Python extension boost 链接 glibc 静态      更新时间:2023-10-16

我正在为 pyton3.6 编写一个扩展。我的开发机器运行 gcc7.3,生产环境操作系统是 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

有人知道吗?谢谢。

原因可能是尽管 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 在上面的命令中使用正确的编号。