Repository navigation
Replies: 1 comment
|
Hey there, I know this is a very old
cmake \
-DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \
-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
-DCMAKE_SYSTEM_NAME=Windows \
+ -DCMAKE_FIND_ROOT_PATH="/usr/x86_64-w64-mingw32;$PWD/python.3.13.0" \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
+ -DPython_INCLUDE_DIR=$PWD/python.3.13.0/tools/include \
+ -DPython_LIBRARY=$PWD/python.3.13.0/tools/python313.dll \
+ -DPYBIND11_USE_CROSSCOMPILING=ON \
+ -DPYTHON_MODULE_EXT_SUFFIX=".cp313-win_amd64.pyd" \
+ -DPYTHON_MODULE_EXTENSION=".cp313-win_amd64.pyd" \
-S . -B build/The green lines represent those that I had to add because of cross-compiling a pybind11 module.
+ if(CMAKE_CROSSCOMPILING)
+ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
+ endif(CMAKE_CROSSCOMPILING)
FetchContent_MakeAvailable(pybind11)
+if(CMAKE_CROSSCOMPILING)
+ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+endif(CMAKE_CROSSCOMPILING)So now, cmake will manage to find the right python and not the one on the host system, and building will also work out.
This is a scaringly complicated process. If it helps, I created a repo where all this is demonstrated step by step, including a GitHub workflow that builds a pyd module on Debian and runs the tests on this module on Windows. There is also a GitLab equivalent in the repo. See the repo here: https://github.com/lvk88/mingw-pipeline-tests I hope this helps. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have a C++ library for which I'm using pybind11 to generate Python bindings. Currently I'm compiling on Linux x86 host for the same target using gcc and everything works fine.
I want to port my library (which only depends on C ++ std libraries) to Windows and I was to keep my current Linux development environment and cross compile the library for Windows using MinGW (from MXE). However when I try to build the python bindings using pybind11, the compilation fails as MinGW cannot find a compatible Python library.
My question is as follows:
If there is a 3rd option I would be most welcome as well (N.B. I cannot compile on Windows and I need to keep my a cross compilation environment (not necessarily MXE)
All reactions