【问题标题】:Cython: Compiling and Cannot Find Library Mac OSX 10.12Cython:编译但找不到库 Mac OSX 10.12
【发布时间】:2017-03-27 20:33:54
【问题描述】:

我刚刚开始使用 Cython,正在尝试编译“Hello World”脚本。我正在尝试使用gcc -Os /User/Documents/Python/Test\ Python/helloCopy.c -I/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -l,但我不知道在-l 之后添加什么。其他论坛页面说“在链接器命令行中包含 -lpython2.7(或您正在使用的任何 Python 版本)”,但这会产生 ld: library not found for -lpython3.5 clang: error: linker command failed with exit code 1 (use -v to see invocation) 我应该将-l 指向特定文件夹吗?

【问题讨论】:

    标签: python c compilation cython


    【解决方案1】:

    我不知道您使用的是什么资源,但this 没有提及-l 标志。它建议

    cython -a helloCopy.pyx
    

    这将创建一个 yourmod.c 文件,并且 -a 开关会生成一个带注释的源代码 html 文件。传递 -h 标志以获得支持标志的完整列表。

    gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python2.7 -o helloCopy.so helloCopy.c
    

    (Linux)

    在 macOS 上我会尝试编译

    gcc -I/usr/bin/python -o helloCopy.so helloCopy.c
    

    使用标准版本的 Python。

    【讨论】:

    • 这两个都产生了Undefined symbols for architecture x86_64: "_PyBytes_FromStringAndSize", referenced from: _PyInit_helloCopy in helloCopy-d342ea.o ___Pyx_InitStrings in helloCopy-d342ea.o "_PyCode_New", referenced from:的错误...一大堆ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
    • 另外,我如何确定我正在使用什么资源?
    • @ConnorTingley 我找到了this,我认为您以前曾将其用作参考。你安装了python-dev 吗?
    • 我想是的,因为我能够成功地包含 python3.5m 文件夹,但我可能完全错了。
    猜你喜欢
    • 2018-08-27
    • 1970-01-01
    • 2015-11-08
    • 2017-05-07
    • 2018-10-05
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多