Compiling and Linking pre-built Windows Python libraries with C++ files on Linux for Windows

Dan Stromberg drsalists at gmail.com
Sat Mar 19 12:42:29 EDT 2022


On Fri, Mar 18, 2022 at 8:03 PM Ankit Agarwal <ankit at applied.co> wrote:

> Hi,
>
> This is a very specific question. I am trying to figure out whether or not
> I can use pre-built python libraries and headers on Windows in a MinGW
> build on Linux. Essentially I have some python and C++ code which interface
> via cython and pybind. I want to build a self contained C++ binary for
> Windows with the MinGW compiler that runs on Linux. For both Cython and
> PyBind, they need to compile with the python headers and link against the
> python DLL in order to run on Windows.
>
> I know that the python DLL specifically are compiled with the MSVC
> compiler, however since it is in C, the ABI between the DLL should be
> compatible with MinGW, and I should be able to import and link against it.
> My question is will this work, or will there be some other problem that I
> might run into.
>
>
I haven't tried this.

However, I used to cross-compile the Linux kernel from Solaris on Sparc to
Intel.  I just had to:
1) Get the relevant headers and libraries on Solaris
2) Deal with the byte sex issues - Sparc is Big Endian, Intel is Little
Endian
3) Natively compile a little bit of code that was needed by the build
process

You appear to be aware of #1.

You probably won't need to worry about #2, since you're going Intel ->
Intel.

#3 could be an issue for you, but it's just a matter of using two different
compilers for some different parts of the build process - one native, one
cross.

I'd try a little hello world first, then worry about your larger project.

You could also put some feelers out about Cython and Pybind too, to see if
they've been used for cross-compilation before.  If yes, you're probably in
like Flynn, otherwise it could potentially turn out to be a big project.

If cross-compilation doesn't work out, you could probably set up a Windows
virtual machine with an sshd, and build on that.

Either way, you may find Wine useful for testing.

HTH.


More information about the Python-list mailing list