distutils 在编译 Windows .dll 时可以使用自定义 .def 来公开额外的符号吗?

发布于 2024-08-23 11:16:53 字数 267 浏览 3 评论 0原文

我滥用 distutils 来编译 Python 的扩展模块,但我没有使用 Python C API,而是使用 ctypes 来与生成的共享库对话。

这在 Linux 中工作得很好,因为它会自动导出共享库中的所有符号,但在 Windows 中,distutils 提供了一个 .def 来仅导出 Python 模块 init 函数。

如何扩展 distutils 以在 Windows 上提供我自己的 .def 以便它导出我需要的符号?

I'm abusing distutils to compile an extension module for Python, but rather than using the Python C API I'm using ctypes to talk to the resulting shared library.

This works fine in Linux because it automatically exports all symbols in a shared library, but in Windows distutils provides a .def to export only the Python module init function.

How do I extend distutils to provide my own .def on Windows so it will export the symbols I need?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅哥哥的热头脑 2024-08-30 11:16:53

如果您使用 Mingw 的 GCC,则可以将 ['-Wl,--export-all-symbols'] 作为 extra_link_args 传递。 IDE 中的某个位置可能有类似的 Visual 设置。

仅当 distutils 选择使用“gcc -mdll”而不是“dllwrap”作为链接器时,此功能才有效。如果您的 ld 版本高于 2.10.90,那么它就会执行此操作(如果您使用的是最新的 Mingw,则应该是这种情况)。起初它对我不起作用,因为我使用 Python 2.2,它有一个与版本解析相关的小错误:它需要 3 个点分隔的数字,因此如果 ld 版本是 2.20,它会回退到 dllwrap...

You can pass ['-Wl,--export-all-symbols'] as extra_link_args if you're using Mingw's GCC. There's probably a similar setting for Visual, somewhere in the IDE.

This works only if distutils chooses to use "gcc -mdll" as a linker instead of "dllwrap". It does so if your ld version is later than 2.10.90, which should be the case if you're using a recent Mingw. At first it didn't work for me because I used Python 2.2 which has a small bug related to version parsing: it expects 3 dot-separated numbers so it falls back to dllwrap if the ld version is 2.20...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文