Cross-compiling sources
Simple Makefile-based compilation
Well-written software (warning: this is highly subjective) should compile like this:
$ make CC=arm-linux-gnueabi-gcc
(adapt if the sources are in another language than C or the architecture is other than arm)
If it fails, check the next section or look in the Known problems part.
Setting up pkg-config
pkg-config can be configured to look into the cross-compilation environment instead of the native one:
# export PKG_CONFIG_LIBDIR="/usr/arm-linux-gnueabi/usr/lib/pkgconfig:/usr/arm-linux-gnueabi/usr/share/pkgconfig" # export PKG_CONFIG_SYSROOT_DIR="/usr/arm-linux-gnueabi"
(These two lines can be found in /root/.bashrc, commented.)
This is automatically set in the environment when using hackable:1's trunk/packages/package.sh with the DEBIAN_ARCH option set.
With ./configure
Using the --host flags with software using autoconf/automake (through the ./configure script) should just work. For example, for the Openmoko Freerunner (ARM EABI):
$ ./configure --host=arm-linux-gnueabi $ make
In this case, the correct binaries are automatically called when using make.
For the Linux kernel
This will configure the kernel for an ARM platform:
$ make ARCH=arm menuconfig
And to actually build the kernel:
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi
Testing the binaries
You may then use your favorite method to upload the binaries to your embedded device:
- NFS share
- SSH file uploads
Known problems
"CC=arm-linux-gnueabi make" fails on linking
When you cross-compile sources without packaging them, you may miss some flags, especially LD flags. The following is a possible error message:
$ CC=arm-linux-gnueabi make [...] /usr/lib/gcc/arm-linux-gnueabi/4.3.2/../../../../arm-linux-gnueabi/bin/ld: skipping incompatible /usr/arm-linux-gnueabi/bin/../../lib/libXtst.so when searching for -lXtst /usr/lib/gcc/arm-linux-gnueabi/4.3.2/../../../../arm-linux-gnueabi/bin/ld: skipping incompatible /usr/arm-linux-gnueabi/bin/../../lib/libXtst.a when searching for -lXtst /usr/lib/gcc/arm-linux-gnueabi/4.3.2/../../../../arm-linux-gnueabi/bin/ld: cannot find -lXtst collect2: ld returned 1 exit status
Here, ld looks for the libraries in /usr/lib instead of /usr/arm-linux-gnueabi/usr/lib even if PKG_CONFIG* env vars are correctly set. You should specify:
CC=arm-linux-gnueabi LDFLAGS="-L/usr/arm-linux-gnueabi/lib -L/usr/arm-linux-gnueabi/usr/lib -Wl,-rpath-link /usr/arm-linux-gnueabi/lib -Wl,-rpath-link /usr/arm-linux-gnueabi/usr/lib" make
and make sure the Makefile uses them.
Also, if you use libtool, you need to pass -inst-prefix-dir /usr/arm-linux-gnueabi to make and a patch in ltmain.sh as in here
Some programs do not compile
There may be a number of causes:
- hard-coded binaries are used to compile or link: native applications may be picked up instead of the cross-compiler, from within badly-written Makefiles for example
