Development/Howto/CrossCompilation

From Mandriva Community Wiki

Jump to: navigation, search
Creating a cross compiler

This page quickly describes the steps used to create a cross compilation package using the gcc srpm

Contents


[edit] Compiling binutils

First, you need to get the srpm of binutils, found on any good mirror. I will use a local mirror for the next example.

Then, you need to setup an rpm building environment, as explained in the RpmHowTo. And then, you need to recompile binutils with a flag :

 [misc@n1 ~] $ rpm --define "cross ppc" --rebuild /SRPMS/main/binutils-2.15.92.0.2-4mdk.src.rpm
Installing /SRPMS/main/binutils-2.15.92.0.2-4mdk.src.rpm
Executing(%prep): /bin/sh -e /home/misc/tmp/rpm-tmp.88205
+ umask 022
+ cd /home/misc/rpm/BUILD
+ cd /home/misc/rpm/BUILD
+ rm -rf binutils-2.15.92.0.2
...
Checking for multiarch file(s): /usr/lib/rpm/check-multiarch-files
Wrote: /home/misc/rpm/RPMS/i586/cross-ppc-binutils-2.15.92.0.2-4mdk.i586.rpm
Wrote: /home/misc/rpm/RPMS/i586/cross-ppc-libbinutils2-2.15.92.0.2-4mdk.i586.rpm
Wrote: /home/misc/rpm/RPMS/i586/cross-ppc-libbinutils2-devel-2.15.92.0.2-4mdk.i586.rpm
Executing(%clean): /bin/sh -e /home/misc/tmp/rpm-tmp.27022
+ umask 022
+ cd /home/misc/rpm/BUILD
+ cd binutils-2.15.92.0.2
+ rm -rf /home/misc/tmp/cross-ppc-binutils-2.15.92.0.2-root
+ exit 0

You need to install those rpm's on your system in order to build a gcc cross compiler.

[edit] Compiling gcc

Since gcc requires gcc to be compiled, you need to bootstrap it. This is simply done by adding a define :

 [misc@n1 ~] $ rpm --define "cross_bootstrap ppc" --rebuild /SRPMS/main/gcc-3.4.3-3mdk.src.rpm
Installing /SRPMS/main/gcc-3.4.3-3mdk.src.rpm
Executing(%prep): /bin/sh -e /home/misc/tmp/rpm-tmp.64546
+ umask 022
+ cd /home/misc/rpm/BUILD
....

You can now install the produced rpm, to start the cross compilation.

[edit] Utilisation of the cross compiler

In order to use the cross compiler, you simply replace cc with this compiler, either with the update-alternatives command, or by changing the CC environment variables.

[edit] Various cross compilation targets

You can either specify an architecture (such as ppc, sparc64, etc) or also give some interesting target such as "i586-mingw32msvc" (use cross mingw32 to compile) to create a win32 cross compiler, that can create a microsoft windows® executable with a simple C source code.

[edit] Other links

Personal tools