【问题标题】:Cannot link a shared library for python无法为 python 链接共享库
【发布时间】:2018-09-22 03:52:15
【问题描述】:

我为apache制作了一个模块,并使用gcc进行编译:

gcc \
    $(apr-1-config --cflags) \
    $(apr-1-config --includes) \
    $(python3.6-config --cflags) \
    -fPIC -DSHARED_MODULE \
    -I/usr/include/httpd/ \
    -c mod_demo.c

但是当我尝试链接 python 库时它不起作用:

ld \
    $(apr-1-config --link-ld) \
    $(python3.6-config --ldflags) \
    -Bshareable \
    -o mod_demo.so \
    mod_demo.o

输出消息是:

ld: -linker not found.

有什么问题?标志是:

[root@demo demo]# python3.6-config --ldflags
-L/usr/lib64 -lpython3.6m -lpthread -ldl  -lutil -lm  -Xlinker -export-dynamic

如果在没有 -Xlinker 的情况下编写标志,它可以正常工作:

 ld \
    $(apr-1-config --link-ld) \
    -L/usr/lib64 -lpython3.6m -lpthread -ldl  -lutil -lm  -export-dynamic \
    -Bshareable \
    -o mod_demo.so \
    mod_demo.o

如何使用来自python3.6-config 的原生标志?-Xlinker 有什么问题?

【问题讨论】:

    标签: linux python-3.x gcc centos7 ld


    【解决方案1】:

    -Xlinker -export-dynamic 是一个告诉 GCC 将 -export-dynamic 传递给链接器的东西。

    您在滥用python3.6-config --ldflags,因为它希望将其输出提供给 GCC,而不是直接提供给 ld。

    试试这个:

    gcc \
        $(apr-1-config --link-ld) \
        $(python3.6-config --ldflags) \
        -shared \
        -o mod_demo.so \
        mod_demo.o
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-25
      • 2020-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多