Cross Compiling

 

Cross compiling software on a host platform to run on a different target used to be an exotic stunt to be performed by the brave and desperate. One had first to configure and build the compiler, assembler, archiver, and linker for the different architecture, then cross-build the other architecture's libraries, and finally the software. This week, while preparing a new release of the CScout refactoring browser I realized that what was once a feat is nowadays a routine operation.

This is all that was needed in order to create a so-called Mach-O binary for the Apple Mac OS X platform. This binary contains code for both the PowerPC and the Intel i386 architecture. All I did was to modify my Makefile's compilation and linking variables CPPFLAGS and LDFLAGS as follows:

CPPFLAGS+=-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc
LDFLAGS+=-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk

On the FreeBSD platform I first had to create an appropriate toolchain. Thus in a directory containing a copy of the FreeBSD source distribution I ran:

for a in amd64 i386 sparc64
do
        export MAKEOBJDIRPREFIX=/home/dds/src/fbsd6/obj/$a
        make toolchain TARGET_ARCH=$a
done
Then, all I had to do was to invoke gmake with appropriate overrides for the C/C++ compilers and the target architecture.
H=/usr/home/dds/src/fbsd6
AMD64BIN=$H/obj/amd64/amd64/$H/src/tmp/usr/bin
SPARC64BIN=$H/obj/sparc64/sparc64/$H/src/tmp/usr/bin
I386BIN=$H/obj/i386/$H/src/tmp/usr/bin

gmake ARCH=amd64 CXX=$AMD64BIN/g++ CC=$AMD64BIN/gcc
gmake ARCH=sparc64 CXX=$SPARC64BIN/g++ CC=$SPARC64BIN/gcc
gmake ARCH=i386 CXX=$I386BIN/g++ CC=$I386BIN/gcc

Comments   Toot! Share


Last modified: Saturday, September 30, 2006 10:32 pm

Creative Commons Licence BY NC

Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.