Followers 0

# Crosscompiling from Linux to Windows

## 4 posts in this topic

OK, so I want to make Windows builds of my game but I'm running Ubuntu. I was expecting to get a Windows computer this month (which I was planning to use to make Windows builds) but that seems like it isn't going to happen so I'm probably stuck trying to crosscompile from Ubuntu instead. Already installed MinGW-w64 (through Software Center, so assume default everything), but I have no idea how to use it.

Basically I need to build these libraries:

• SDL 2
• PhysicsFS
• libpng
• zlib
• libogg
• libvorbis
• vorbisfile

PhysicsFS uses CMake so that's probably easy (just tell CMake to use MinGW-w64 to build). SDL2 includes a CMake script too so I could attempt to use that (not sure how well it works though). The rest of the libraries I have absolutely no idea how, though.

Then after that I need to get the game build for Windows. Again, no idea. Currently using Code::Blocks. I noticed MinGW-w64 isn't detected, but I wonder if I could just clone the GCC settings and change the directories (since otherwise it seems to be identical). If somebody else has a better solution tell me. Otherwise I may need to make a makefile and I have no idea how to make it to work properly with the crosscompiler.

Any help is appreciated! (this is also to learn how to use a crosscompiler!)

0

##### Share on other sites

In the configuration script that mostly come with the source packages use the --host --target parameters

But better have a look in the lists of parameters with ./configure --help

It may work.

0

##### Share on other sites

Yeah, but I have no idea what to fill in those parameters (since I never used configure before except as "./configure"). Also, zlib isn't being very helpful:

sik@host221:~/Descargas/zlib-1.2.8$./configure --help usage: configure [--const] [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX] [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR] [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"] Either it's not listing all possible parameters, or it's not making it easy to crosscompile. Odd, considering what kind of library it is. 0 #### Share this post ##### Link to post ##### Share on other sites Currently using Code::Blocks. I noticed MinGW-w64 isn't detected, but I wonder if I could just clone the GCC settings and change the directories (since otherwise it seems to be identical). That works, but you must change the executable prefix, not the path (they're normally all in the same location). Your /usr/bin folder looks something like this (that's mine, actually): me@ubuntu:/usr$ ls -l bin | grep gcc
-rwxr-xr-x 1 root root         428 Mai  7  2006 c89-gcc
-rwxr-xr-x 1 root root         454 Apr 11  2011 c99-gcc
lrwxrwxrwx 1 root root           7 Okt 12  2013 gcc -> gcc-4.8
-rwxr-xr-x 1 root root      357344 Jun 19  2013 gcc-4.6
-rwxr-xr-x 1 root root      775888 Nov 15  2013 gcc-4.8
-rwxr-xr-x 1 root root       26968 Nov 15  2013 gcc-ar-4.8
-rwxr-xr-x 1 root root       26968 Nov 15  2013 gcc-nm-4.8
-rwxr-xr-x 1 root root       26968 Nov 15  2013 gcc-ranlib-4.8
-rwxr-xr-x 1 root root      349248 Dez 13  2012 i686-w64-mingw32-gcc
-rwxr-xr-x 1 root root      349256 Dez 13  2012 i686-w64-mingw32-gcc-4.6
lrwxrwxrwx 1 root root           7 Okt 12  2013 x86_64-linux-gnu-gcc -> gcc-4.8
lrwxrwxrwx 1 root root           7 Jun 19  2013 x86_64-linux-gnu-gcc-4.6 -> gcc-4.6
lrwxrwxrwx 1 root root           7 Nov 15  2013 x86_64-linux-gnu-gcc-4.8 -> gcc-4.8
lrwxrwxrwx 1 root root          10 Nov 15  2013 x86_64-linux-gnu-gcc-ar-4.8 -> gcc-ar-4.8
lrwxrwxrwx 1 root root          10 Nov 15  2013 x86_64-linux-gnu-gcc-nm-4.8 -> gcc-nm-4.8
lrwxrwxrwx 1 root root          14 Nov 15  2013 x86_64-linux-gnu-gcc-ranlib-4.8 -> gcc-ranlib-4.8
-rwxr-xr-x 1 root root      349248 Dez 13  2012 x86_64-w64-mingw32-gcc
-rwxr-xr-x 1 root root      349256 Dez 13  2012 x86_64-w64-mingw32-gcc-4.6

Note how all the cross compilers (including the x64 Linux "cross" compiler, which is really just a symlink to the native compiler that doesn't have a prefix) have a different name prefix.

Of course that's only for making Code::Blocks work, for cmake or configure you need to do the obscure build/host/target triplet dance.

Unluckily, the GNU build system is where it gets nasty, even after years, I still need several attempts to get it right every single time I try. From the official docs:

The relationship between build, host, and target have been cleaned up: the chain of default is now simply: target defaults to host, host to build, and build to the result of config.guess. [...]

configure enters cross-compilation mode if and only if --host is passed. That's the short documentation.

Now of course, it also tells you further down that you are not to provide host without build, since that is "fragile" (whatever that means). Great, huh. So, in short, you need to provide these:

--build=... The system on which the package is built. That is, x86_64-linux-gnu-gcc or whatever it is on your box (probably exactly that!).
--host=...  The system where built programs and libraries will run. That's x86_64-w64-mingw32-gcc or whatever you choose it to be.

me@ubuntu:/usr\$ x86_64-w64-mingw32-gcc -v
Using built-in specs.
COLLECT_GCC=x86_64-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-w64-mingw32/4.6/lto-wrapper
Target: x86_64-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include'
--mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var
--libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib
--enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs
--with-gxx-include-dir=/usr/include/c++/4.6 --with-as=/usr/bin/x86_64-w64-mingw32-as --with-ld=/usr/bin/x86_64-w64-mingw32-ld
gcc version 4.6.3 (GCC)

As you can see, this compiler was built with --build=x86_64-linux-gnu and --target=x86_64-w64-mingw32. The "target" is what the compiler builds executables for, so that's what you want to use as "host".

For cmake, it's described here.

2

##### Share on other sites

EDIT: forget everything I wrote before (check the edit history if you're curious), turns out it wasn't doing what I thought it was. When I figure out it all I'll post the details of what to do. At least it does seem like I could build the libraries (but installing them is a whole different issue).

Edited by Sik_the_hedgehog
0

## Create an account

Register a new account