fix: add NumPy 2.x and MinGW build support#138
Closed
longtsing wants to merge 1 commit intoCyanideCN:masterfrom
Closed
fix: add NumPy 2.x and MinGW build support#138longtsing wants to merge 1 commit intoCyanideCN:masterfrom
longtsing wants to merge 1 commit intoCyanideCN:masterfrom
Conversation
Auto-fix Cython C code for MinGW GCC compatibility. Support both NumPy 1.20+ and 2.x with NPY_1_7_API_VERSION. Add cross-platform build configuration.
Contributor
|
10.28 已测试在windows10,py3.11的环境下,先安装numpy=0.23,后安装cinrad,导入错误已不再出现。 |
Contributor
Author
|
很奇怪,我这边测试是出错,或者您看看numpy 的具体版本呢? |
Contributor
我是说安装了你这个fix版本的cinrad就没出现导入错误了… |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复了 #128
主要解决了:
问题1:使用 NumPy 2.x 环境时导入 PyCINRAD 遇到错误;根本原因:
NumPy 2.0 改变了 C API 的 ABI(Application Binary Interface)
使用 NumPy 1.x 编译的扩展模块无法在 NumPy 2.x 环境中运行
需要使用 NumPy 稳定 API (NPY_1_7_API_VERSION) 来实现跨版本兼容
问题2: MinGW-w64 编译失败
Windows 用户使用 MinGW-w64 编译时遇到错误:
根本原因:
Cython 生成的编译时检查代码不符合 C 标准
MinGW GCC 严格遵守标准,拒绝编译
MSVC 编译器较为宽松,可以通过
本次修改通过在 Cython 源文件中使用 NumPy 1.7 稳定 API(NPY_1_7_API_VERSION)实现了对 NumPy 1.20+ 和 2.x 的跨版本兼容性,同时在 setup.py 中添加自动修复逻辑,使用正则表达式删除 Cython 生成的不符合 C 标准的 enum 检查代码,从而解决了 MinGW GCC 编译失败的问题,最终实现了一次编译即可在所有主流平台(Windows MSVC/MinGW、Linux、macOS)和不同 NumPy 版本下正常运行的目标。