Difference between revisions of "Cross-compiling Windows version from Linux"

From Armagetron
m (Reverted edits by 69.61.60.178 (Talk); changed back to last version by Jonathan)
(→‎CMake: Added this section)
Line 59: Line 59:
  
 
This will configure and build the dedicated server with a recent trunk checkout.  The dedicated server that's built this way has a few issues to work out, but it'll run in Win98 and Wine, the difference being that in Wine you can't connect a client to it.
 
This will configure and build the dedicated server with a recent trunk checkout.  The dedicated server that's built this way has a few issues to work out, but it'll run in Win98 and Wine, the difference being that in Wine you can't connect a client to it.
 +
 +
 +
=CMake=
 +
It is almost possible to cross-build a dedicated server on this branch with linux as build platform and windows as host, so I'm documenting this here
 +
==Dependencies==
 +
Many dependencies had cross-building packages in archlinux's user contributed repository, so I'm only documenting the ones I had trouble with.
 +
===protobuf===
 +
The build process of protobuf includes some .proto compiling with the protoc utility. Since you're going to build protobuf for windows on a linux box, you won't be able to use the protoc you'll build, so you need to have another protoc built for linux with the """same version""" as what you are building.
 +
 +
Once you have built it(or if it is in your system), you need to tell protobuf's configure script where prtoc is:
 +
./configure --host=i486-mingw32 --with=protoc=/path/to/protobuf-x.x.x/src/protoc
 +
 +
One tiny bug will however cause protobuf 2.3.0 not to compile for windows on GCC. It is being fixed for protobuf 2.3.1[http://code.google.com/p/protobuf/issues/detail?id=155]. You can fix it by editing <code>src/google/protobuf/compiler/subprocess.h</code> at line <code>79</code>: Change
 +
static string Subprocess::Win32ErrorMessage(DWORD error_code);
 +
to
 +
static string Win32ErrorMessage(DWORD error_code);
 +
 +
==Armagetronad itself==
 +
===Toolchain file===
 +
This is the file one usually uses with cmake to tell it what tools to use and what platform to build for. It is optionnal to make one, but it is very convenient to do one and it is project-independent.
 +
SET(CMAKE_SYSTEM_NAME i486-mingw32)
 +
SET(CMAKE_SYSTEM_VERSION 1)
 +
SET(CMAKE_C_COMPILER /usr/bin/i486-mingw32-gcc)
 +
SET(CMAKE_CXX_COMPILER /usr/bin/i486-mingw32-g++)
 +
SET(CMAKE_FIND_ROOT_PATH /usr/i486-mingw32/)
 +
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 +
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
 +
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
 +
 +
You will also need to make a symlink from <code>/usr/i486-mingw32/usr</code> to <code>/usr/i486-mingw32/</code>, because cmake's model assumes usual prefix for cross-compiled is <code>/usr/i486-mingw32/usr/</code> while most applications actually use <code>/usr/i486-mingw32/</code>, which is somewhat indeed a weird choice.
 +
ln -s /usr/i486-mingw32/ /usr/i486-mingw32/usr
 +
===Configuring===
 +
Configuring should go relatively flawlessy, since no results from the host platform should be needed.
 +
 +
Simply tell cmake you want to use the toolchain file you just created
 +
cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/your/toolchainfile.cmake -DDEDICATED=yes .
 +
 +
===Buidling===
 +
For the dedicated server (client doesn't configure properly yet), type
 +
make armagetronad-dedicated

Revision as of 13:14, 14 February 2010

Just collecting cross-compilation notes.

Setting up the cross compiler under linux

Check your distribution for mingw packages. If it has it, install them. If not, try this:

http://www.libsdl.org/extras/win32/cross/

Export some environment variable:

export CC=i586-mingw32msvc-gcc
export CXX=i586-mingw32msvc-c++
export LD=i586-mingw32msvc-ld
export AR=i586-mingw32msvc-ar
export AS=i586-mingw32msvc-as
export NM=i586-mingw32msvc-nm
export STRIP=i586-mingw32msvc-strip
export RANLIB=i586-mingw32msvc-ranlib
export DLLTOOL=i586-mingw32msvc-dlltool
export OBJDUMP=i586-mingw32msvc-objdump
export RESCOMP=i586-mingw32msvc-windres

You might want those in a script.

Libraries

You'll need to use the same configure command to configure and install the libraries. Get libSDL and libxml2 and do this:

./configure --host=i586-mingw32msvc --prefix=/usr/i586-mingw32msvc

Prefix is the location of your cross-compiler, it should have "bin", "lib", and "include" in it.

To get libxml2 to cross-compile, use this as your configure command:

./configure --host=i586-mingw32msvc --prefix=/usr/i586-mingw32msvc --with-python=no

Armagetron Advanced

You need to set some influential environment variables to make it configure.

XML2_CONFIG=/path/to/cross-compiled/xml2-config SDL_CONFIG=/path/to/cross-compiled/sdl-config

Example:

XML2_CONFIG=/usr/i586-mingw32msvc/bin/xml2-config SDL_CONFIG=/usr/i586-mingw32msvc/bin/sdl-config ../../armagetronadnew/configure --host=i586-mingw32msvc --prefix=/usr/i586-mingw32msvc --disable-sound

Currently it's failing for me with this line:

 checking for glVertex3f in -lopengl32... no
 OpenGL not found. Maybe it needs X11 to compile? Checking that...

Dedicated Server

Same as above, only try this configure line instead:


XML2_CONFIG=/usr/i586-mingw32msvc/bin/xml2-config SDL_CONFIG=/usr/i586-mingw32msvc/bin/sdl-config CFLAGS="-I/usr/i586-mingw32msvc/include -DNO_SOCKLEN_T" CXXFLAGS="-I/usr/i586-mingw32msvc/include" ../../armagetronadnew/configure --host=i586-mingw32msvc --prefix=/home/dave/Projects/armagetronad/aabuild/win32install --disable-sound --disable-glout --disable-binreloc

This will configure and build the dedicated server with a recent trunk checkout. The dedicated server that's built this way has a few issues to work out, but it'll run in Win98 and Wine, the difference being that in Wine you can't connect a client to it.


CMake

It is almost possible to cross-build a dedicated server on this branch with linux as build platform and windows as host, so I'm documenting this here

Dependencies

Many dependencies had cross-building packages in archlinux's user contributed repository, so I'm only documenting the ones I had trouble with.

protobuf

The build process of protobuf includes some .proto compiling with the protoc utility. Since you're going to build protobuf for windows on a linux box, you won't be able to use the protoc you'll build, so you need to have another protoc built for linux with the """same version""" as what you are building.

Once you have built it(or if it is in your system), you need to tell protobuf's configure script where prtoc is:

./configure --host=i486-mingw32 --with=protoc=/path/to/protobuf-x.x.x/src/protoc

One tiny bug will however cause protobuf 2.3.0 not to compile for windows on GCC. It is being fixed for protobuf 2.3.1[1]. You can fix it by editing src/google/protobuf/compiler/subprocess.h at line 79: Change

static string Subprocess::Win32ErrorMessage(DWORD error_code);

to

static string Win32ErrorMessage(DWORD error_code);

Armagetronad itself

Toolchain file

This is the file one usually uses with cmake to tell it what tools to use and what platform to build for. It is optionnal to make one, but it is very convenient to do one and it is project-independent.

SET(CMAKE_SYSTEM_NAME i486-mingw32)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_C_COMPILER /usr/bin/i486-mingw32-gcc)
SET(CMAKE_CXX_COMPILER /usr/bin/i486-mingw32-g++)
SET(CMAKE_FIND_ROOT_PATH /usr/i486-mingw32/)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

You will also need to make a symlink from /usr/i486-mingw32/usr to /usr/i486-mingw32/, because cmake's model assumes usual prefix for cross-compiled is /usr/i486-mingw32/usr/ while most applications actually use /usr/i486-mingw32/, which is somewhat indeed a weird choice.

ln -s /usr/i486-mingw32/ /usr/i486-mingw32/usr

Configuring

Configuring should go relatively flawlessy, since no results from the host platform should be needed.

Simply tell cmake you want to use the toolchain file you just created

cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/your/toolchainfile.cmake -DDEDICATED=yes .

Buidling

For the dedicated server (client doesn't configure properly yet), type

make armagetronad-dedicated