Howto: Cross compiling

justincormack edited this page Oct 5, 2014 · 5 revisions
Clone this wiki locally

The build scripts are all set up for cross compiling, and it should be relatively straightforward.

If the environment variable $CC is set, its value is used as the compiler instead of cc. This allows not only to select between compiling with gcc or clang, but also allows to specify a crosscompiler. If $CC is set and does not contain the value cc, gcc, or clang the script assumes a crosscompiler and will by default use tools with names based on the target of $CC with the format target-tool (e.g. target-nm).

Crosscompiling for an ARM system might look like this (first command is purely informational):

$ arm-linux-gnueabihf-gcc -dumpmachine
$ env CC=arm-linux-gnueabihf-gcc ./ [params]

Since the target is arm-linux-gnueabihf, arm-linux-gnueabihf-nm etc. must be found from $PATH. The assumption is that the crosscompiler can find the target platform headers and libraries which are required for building the hypercall library. You can override the defaults by setting $AR, $NM and/or $OBJCOPY in the environment before running the script.


If you have a multilib Linux distro things are very easy, you should be able to just use the instructions above without changes.

export CC=arm-linux-androideabi-gcc


NetBSD lets you build cross compilers easily using the script. Something along these lines should work - you need to build distribution not just tools, and you must set sysroot.

./ -U -m sparc64 tools
./ -U -m sparc64 distribution

export PATH=$PWD/obj/tooldir.NetBSD-7.0_BETA-amd64/bin:$PATH
export CC=sparc64--netbsd-gcc
export NM=sparc64--netbsd-nm
export AR=sparc64--netbsd-ar
export OBJCOPY=sparc64--netbsd-objcopy

./ -F CFLAGS=--sysroot=..../src/obj/destdir.sparc64