Nathan Coulson

Cross Compiling from Linux

I prefer doing my development from linux, but I would still like to compile my software for other architectures (OSX, Windows, perhaps dos). Especially if I can build Makefile scripts so one command can build for all architectures.

x86_64-w64-mingw32 (Windows 32bit & 64bit)

The mingw-w64 project has been a godsend, it allows me to compile 32bit & 64bit software in the same toolchain. I believe it can also target WinCE, but I have yet to attempt this. gcc can link directly to dll files (if the symbol table is present). At the time this was posted, there seems to be 2 choices, trunk and the 1.0 snapshot. This was modified from my i686-pc-mingw32 toolchain, with some information from


MingwRT Headers

GCC Requires some files from the mingw package to compile, so we will install them first


GCC Pass1

We will start by compiling a basic gcc compiler, just enough to compile the mingw headers. The full gcc suite requires us to install the mingw headers/libraries first

MingwRT Libraries

Now a full install of the mingw headers and libraries

GCC Pass2

And now to do a full gcc install

i686-pc-mingw32 (Windows 32bit)

I no longer use this compiler for my own projects, This will build a 32bit linux to windows toolchain using binutils/gcc/mingw, and in theory x86_64-w64-mingw32 should be able to do anything this compiler did

Cavets: The mingw32 project targets an earlier gcc. This information is here for historic information.




GCC - Pass 1

Without the mingw headers & libraries installed, we can only build a minimal gcc at this time.

Win32 API

To compile, this requires us to have an extracted mingw tarball at ../mingw. It also requires a patch to fix a -I path

Mingw Runtime - Pass 1

Unfortunately, we cannot compile the libmingwthrd.a until we install the full GCC suite. For now, just disable it. This package does not use gcc's search paths, so we force it to search in the sys-root for the w32api files

GCC - Pass 2

Now that we have the mingw & win32 headers & libraries installed, we can build a fully functional gcc

Mingw Runtime - Pass 2

And of course, build the entirety of the mingw runtime

x86_64-apple-darwin10 (OSX)

A linux to OSX Cross Compiler. By default, targets 64bit osx, but if you pass -m32 to gcc, it will compile for 32bit. I use odcctools for the linker, and gcc. Most of the articles I have read, suggest that using apple's version of gcc will lead to less headaches in the future, but I have not done any research into installing apple's gcc on a linux machine. It looks like odcctools upstream is no longer being updated, as there are later versions of cctools. At this time, GCC 4.7.1 failed to work as it was calling -no_compact_unwind. It looks like this flag is not present in the cctools used by odcctools.

Below is a list of related links, that may be of use



The download for xcode, is in the form of a image, and requires a bit of processing to access.

Now, we need to extract the libraries


Note: This requires gcc-4.4.6 or earlier, compiled for a 32bit host. I had some linking problems to, so I temporairly moved it

Binutils at this time, does not have enough support for Mach-O at this time. It does not sound like this is a goal for binutils to support.


It appears that the latest gcc has some tests that do not like to run when cross compiling. To get around this, I set the variables manually in a config.cache file (Allows building libobjc), as well as applying a patch I found at GCC Bug 47836. There is a thread discussing the situation at which shows the workaround below. objc++, and c++ have simular failures that can be worked around, but I have yet to research that.