Cross-Compiling with GHC?

Simon Marlow simonmar at
Wed Oct 19 05:04:39 EDT 2005

On 18 October 2005 20:17, Rich Fought wrote:

> GHC noob here, trying to compile a small app for a Linux/PPC target
> from a Linux/x86 host.
> I take it this must be doable, since it is possible to build GHC for
> new platforms and GHC itself is written in Haskell.
> I'm just trying to find out if anyone has formulated a guide to this
> already, before I jump in (and I did try Google
> without much luck).  I'm afraid building GHC for the target is not an
> option.
> My first thought to try is to build an unregisterised GHC on x86 from
> scratch and use it to compile my app to C code,
> which I can then cross-compile to PPC.  Something tells me however
> that this C code still may have some x86 specific
> stuff in it.

This is possible, but far from easy.

The kind of cross-compilation we do to port GHC to a new platform isn't
full cross compilation - we compile Haskell to C on the host, and then C
to object code on the target system.  You can do the same to compile
your app, but remember that you need all the libraries and the RTS
compiled for the target too.  Basically GHC is a special case of an app
that we cross-compile in this way.

If you want to try this, you'd need to proceed something like this:

  - follow the porting instructions, build the libraries and RTS
    on the target, but stop before building GHC

  - put your app in the GHC build tree.  Generate unregisterised
    .hc files on the host, take them to the target and build there.

I've ommitted a *lot* of details.  This plan works in theory.

Alternatively, you could try to make GHC do proper cross-compiling,
using a cross-toolchain on the host system.  This would have more
lasting value, at least.  Definitely a fair bit of work though.


More information about the Glasgow-haskell-users mailing list