Cross compiling

Kai Ruottu karuottu@mbnet.fi
Thu May 31 16:59:00 GMT 2007


Yan Seiner wrote:
> Kai Ruottu napsal(a):
>>
>>
>> A totally normal and totally sane crosstoolchain made from the 
>> binutils and GCC sources and the prebuilt Debian/ARM
>> libraries could really be something very wise!
> OK, how do I go about finding/building one?
 The "Scratchbox" :

     http://www.scratchbox.org/

could be one prebuilt toolchain for the lazy... It is based on Debian 
and "You should be able to run Scratchbox on any Linux distribution".  
But if your host is something else like Windows/Cygwin or 
Sparc/Solaris10 then of course these prebuilt (host)
binaries will not work....  And if your $target system uses some other 
glibc version than that in scratchbox, then it is not suitable.
Generally all those Debian-made glibcs are available in the 
'pool/main/g/glibc' directories in the Debian archives so getting older
glibcs from there will succeed always.

 > Could you please provide me with a link or some guidance as to how to 
build a cross-toolchain using the standard Debian stuff?

The GNU binutils and GCC sources should have README's and INSTALL's to 
tell how to configure and build them. The
base configure command however is as simple as :

    $SRC/configure --prefix=$prefix --host=$host --target=$target 
--with-sysroot=$sysroot

The $SRC is the main directory for the sources like 
'.../binutils-2.17.50.0.12' or '.../gcc-3.3.6'.  Configuring in a separate
$BUILD directory is recommended but I myself have always used a 'build' 
subdir in the main sources as that "separate
build directory" - generally the configure shouldn't care what is below 
that 'build' or care about a 'build' subdir in the main
sources.  "Alien language speakers" like the Swedes could use a 'bygga', 
the Germans a 'bauen' instead of the 'build'...

The $prefix is the wished install prefix, recommendations like 
'/opt/gcc' or '/opt/gnu' do exist for SVR4/Unix, the default
is '/usr/local' - this will be used if no '--prefix=$prefix' is used.  
The $host is the cross host, it will be 'guessed' via 'config.guess'
if no '--host=$host' is used. The '--target=$target' however is 
obligatory in a cross toolchain. The '--with-sysroot=$sysroot'
tells where the prebuilt target C library (extracted from the Debian 
glibc '.deb' archives,  these are really archives made with
'ar' and each one contains a 'data.tar.gz' tarball keeping the real 
stuff) will be put in its original native install scheme, ie below
that $sysroot.  One recommendation could be '/opt/host-$target' for 
this, telling that there one has alien stuff for the $target
host...

After extracting the target glibc into that $sysroot and configuring 
first the binutils using the previous "simple" configure command
and after the build doing 'make install', just the same configure 
command should work also with the GCC sources and the build
succeed too!   But usually a Linux targeted GCC requires extra configure 
options like '--enable-shared', '--enable-threads',
'--with-system-zlib', '|--enable-__cxa_atexit'|....  The two first can 
be defaults now.  If one knows what these are for, then
one can use them...  The default CPU variation can be set via 
'--with-cpu=armXYZ'  where XYZ is some ARM variation. This
causes the produced GCC to be tuned to generate code for that as 
default.  And usually one uses the '--enable-languages=c,c++'
to get only the C and C++ compilers. After building GCC  one installs it 
and can be happy with it... Maybe some option was
forgotten in the GCC configure, like '|--enable-tls' or 
'||--with-float=|type' and a reconfigure and rebuild is needed.



More information about the Gcc-help mailing list