-
Notifications
You must be signed in to change notification settings - Fork 916
Description
🐛 Bug Reports
When trying to cross-compile a python extension for windows on linux using the mingw target I get the following error:
$ cargo build --target x86_64-pc-windows-gnu
error: failed to run custom build command for `pyo3 v0.13.0`
Caused by:
process didn't exit successfully: `./target/debug/build/pyo3-7cf3ac8bb8af293b/build-script-build` (exit code: 1)
--- stderr
Error: "Py_ENABLE_SHARED is not defined"
pyconfig.h from python 3.9.1 for windows (built with the MSVC compiler), which I have installed, contains the following lines:
/* For Windows the Python core is in a DLL by default. Test
Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
#if !defined(MS_NO_COREDLL) && !defined(Py_NO_ENABLE_SHARED)
# define Py_ENABLE_SHARED 1 /* standard symbol for shared library */
# define MS_COREDLL /* deprecated old symbol */
#endif /* !MS_NO_COREDLL && ... */
When I manually add the line
#define Py_ENABLE_SHARED 1
to pyconfig.h the error disappears.
I believe the following code fails to parse C headers with white space between # and define,
as well as with the comments:
https://github.com/PyO3/pyo3/blob/master/build.rs#L224
The C header parsing code should somehow be restricted to generated pyconfig.h headers only.
Manually written pyconfig.h from python for MSVC does not work.
🌍 Environment
Arch Linux
python 3.9.1
mingw-w64-python39-bin 3.9.1 <- this is the MSVC-compiled python, not the MinGW-compiled python
rustc 1.48.0
pyo3 0.13.0