python - 在 Mac Os 中编译和链接 Python 模块
问题描述
我正在开发一个 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 源代码编译的。
解决方案
好的。这是我以前的:
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。
推荐阅读
- sql - 将分隔字符串拆分为多列和多行
- javascript - 在 js 中使用或条件的更好方法
- python - 根据两列比较和排列数据框中的行?
- java - 使用Java中的字符串库,给定字符串中子字符串的最大连续重复次数
- java - 如何在java中的字符串数组之间添加逗号/和
- json - 使用别名/别名路径时,Webpack 无法导入 .json 文件
- python - response['Items'] 返回一个空列表是否有原因?我能够打印测试功能的事件参数
- android - 如何在颤动中获取复杂的 Json 对象?
- reactjs - MaterialUI MenuItem 道具名称
- c# - 仅限特定项目下的 MongoDB 超时