【问题标题】:Compiling and linking Python module in Mac Os在 Mac Os 中编译和链接 Python 模块
【发布时间】:2023-03-11 04:02:01
【问题描述】:

我正在开发一个 Python 模块。我有 C 源文件和一个编译库。我在 Mac Os 中链接时遇到问题,所以我按照Python runtime_library_dirs doesn't work on Mac 提供的说明进行操作。

这篇文章说在 Mac Os 中链接时应该添加额外的链接参数。它还说应该使用 install_name_tool 来更改库的安装名称。

但是,我在使用 install_name_tool 时收到此错误消息:

string table not at the end of the file (can't be processed) in file:

该库是从 Go 源代码编译的。

【问题讨论】:

  • 请包含用于构建库的确切命令(来自 Go 源代码)。
  • 现实检查:要为 CPython 创建一个模块,您应该以提供 C 兼容“存档”或库的方式构建您的 Go 代码——也就是说,您是应该使用带有c-archivec-shared 值之一的-buildmode 选项。进一步的构建过程(将使用该存档/库)应该根据生成的人工制品的类型进行操作。
  • 这是从 Go 编译库的命令:go build -buildmode=c-archive -o $(BUILLDIB_DIR)/mylib.a $(LIB_FILES)
  • 它在 Linux 上运行良好。问题在于 Mac OS 和设置安装名称。
  • 我找到了一些可能对我有帮助的东西。向 Go c 编译器添加参数。

标签: python c go


【解决方案1】:

好的。这是我以前的:

ext_modules = [Extension("_mypymod", ["mymod.c"],
                         extra_link_args=[],
                         depends=[],
                         libraries = [':mylib.a'],
                         library_dirs = [
                             lib_path
                         ],
                   )],

这在 MacOS 中不起作用。应该是这样的:

ext_modules = [Extension("_mypymod", ["mymod.c"],
                             extra_link_args=[lib_path + '/mylib.a'], #full path to the library
                             depends=[],
                       )],

这适用于 linux 和 Mac。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    • 1970-01-01
    • 2012-09-17
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    相关资源
    最近更新 更多