Skip to content
Advertisement

How to cross-platform compile on windows for linux using gcc?

My aim is to create cross-platform C++ python modules. I’m usingCyther (cross-platform The Cross-Platform Cython/Python Compiler).

Cyther uses GCC to compile modules and gives the user the ability to add GCC command-line args.

So, I need run compiler on Windows, but compile for Linux. What args I must pass to GCC to compile a module for Linux (or other platform)?

Is this possible, if so how?

Advertisement

Answer

Gcc must be built separately for each compilation target. It can be built for any target on any host. The target you need is i386-linux-gnu (or often i586-linux-gnu) for 32-bit and x86_64-linux-gnu for 64-bit Linux.

Note that it provides separate binaries, i386-linux-gnu-gcc, x86_64-linux-gnu-gcc etc. Parameters are then the same.

I am not sure anybody provides that, but you can build it yourself. A tool to help you with that is described in C++ cross-compiler from Windows to Linux.

Or you can go the simpler way and build on Linux (including cross-compilation to Windows). This kind of things is just so much easier on a decent Linux distribution.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement