C++ Python模块在MacOS上链接

发布于 2025-01-22 06:41:53 字数 988 浏览 2 评论 0原文

我正在MacOS上构建C ++ Python模块。

在我的计算机上,我有Python,安装在目录/library/frameworks/python.framework/versions/3.9中。我正在指定python的目录为-i/library/frameworks/python.framework/framework/versions/3.9/headers和libraries Directory as > limral/frame/python.framework/versions/versions/versions /3.9/lib -lpython3.9

因此,它可以在我的计算机和其他机器上构建良好,并在其中安装到/library/frameworks/python.framework/versions/versions/3.9中。

但是,当我将图书馆移至机器时,将Python安装到另一个文件夹中,例如/usr/usr/local/cellar/ [email  procepted] /3.9.12/frameworks/python.frameworks/versorwork/versorwork/versions/3.9,我会得到导入模块错误。

otool -l _mymodule.so命令返回过硬编码的绝对路径到/library/frameworks/python.frameworks/versorwork/versions/3.9。我知道,我可以使用install_name_tool更改路径,但是我不想询问并解释我的模块用户来执行此操作,并建立符号链接。

如何使模块更便宜,而Python安装路径独立?

I'm building a C++ python module on MacOS.

On my machine I have python, installed in directory /Library/Frameworks/Python.framework/Versions/3.9. I'm specifing python includes directory as -I/Library/Frameworks/Python.framework/Versions/3.9/Headers and libraries directory as -L/Library/Frameworks/Python.framework/Versions/3.9/lib -lpython3.9.

So it builds good and runs good on my machine and other machines, where python is installed into /Library/Frameworks/Python.framework/Versions/3.9.

But when I move my library to machine, where python is installed into another folder, like /usr/local/Cellar/[email protected]/3.9.12/Frameworks/Python.framework/Versions/3.9, I'm getting import module error.

otool -L _mymodule.so command returns hardcoded absolute path to /Library/Frameworks/Python.framework/Versions/3.9. I know, that I can change the path using install_name_tool, but I don't want to ask and explain my module users to do that, as well as to make a symlink.

How can I make module more portable and python install path independent?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文