Difference between revisions of "Cross-compiler"

From Pandora Wiki
Jump to: navigation, search
(Added my interpretation of DJWillis's Cross Compiler.)
m (corrected the links to cloudef's solution)
 
(27 intermediate revisions by 11 users not shown)
Line 1: Line 1:
One of the ways to compile your applications to the ARM architecture is through a cross-compiler.
+
One of the ways to compile your applications to the ARM architecture is through a cross-compiler.  This will allow you to compile applications for the ARM architecture on a different system.  This is good if you want to develop for the Pandora but are still waiting to receive it, or if you have an application that takes too much memory or drive-space to effectively compile on the Pandora itself.  At the moment, there are 4 different ways you can set up a cross compiling environment.
  
== Using the SDK-Installer ==
+
These options are sorted in '''order of preference'''.  Option two is preferred over three, etc.
 +
 
 +
== A native compilation solution (with optionally distcc) ==
 +
http://cloudef.pw/pandora/dchrt/
 +
 
 +
Instructions: [http://cloudef.pw/pandora/dchrt/README here]
 +
2013
 +
 
 +
The chroot and most of the tools are by urjaman, some of the ipk's and mirroring/hosting by Cloudef.
 +
< Cloudef> urjaman: make it "Obvious solution for elitists"
 +
 
 +
== Ivanovic's CodeSourcery-Based Cross Compiler ==
 +
{{warning|This toolchain won't work on a pure 64bit system.}}
 +
This toolchain is based on previous codesourcery toolchain attempts but uses the packages that openpandora relies on. It should work for every Linux system that can make use of x86 binaries (meaning x86 systems as well as amd64 systems with multilib support). A detailed explanation of the SDK as well as the script required to install it are available in [http://boards.openpandora.org/index.php?/topic/7147-crosscompiler-toolchain-based-on-openpandoraorg-ipks/ this forum thread]. 2012
 +
 
 +
'''Notes''':
 +
* This toolchain works on a 64-bit system, assuming 32-bit compatibility libraries are installed. On Debian, they can be installed with:
 +
<source lang="bash">aptitude install ia32-libs-dev</source>
 +
 
 +
 
 +
== Sebt3's Yactfeau ==
 +
http://www.gp32x.com/board/index.php?/topic/58490-yactfeau/
 +
2011
 +
'''Notes''':
 +
* This toolchain works on a 64-bit system, assuming 32-bit compatibility libraries are installed.  On Debian, they can be installed with:
 +
<source lang="bash">aptitude install ia32-libs-dev</source>
  
Cpasjuste on the GP32X forums has made a nice script to get a build environment and libraries installed on Ubuntu/Debian systems. Download links and a brief explanation can be found in [http://www.gp32x.com/board/index.php?/topic/52343-pandora-sdk-installer/ this thread].
+
=== Using the Toolchain ===
 +
# If you don't already have a Linux-based system you want to use, download and run the [http://sebt3.openpandora.org/buildtools/?f=pandora-virtualbox-image.7z Pandora VirtualBox Image].
 +
# Remove your previous installation by running (default password is devel):
 +
#:<source lang="bash">sudo rm -rf /usr/local/angstrom/arm/*</source>
 +
# Download the [http://sebt3.openpandora.org/buildtools/?f=pandora-toolchain-20110313.tar.bz2 toolchain] ([http://sebt3.openpandora.org/buildtools/pandora-toolchain-20110313.torrent torrent]).
 +
# Unpack the toolchain:
 +
#: <source lang="bash">sudo tar -C /usr/local/angstrom/arm -xjf pandora-toolchain-20110313.tar.bz2</source>
 +
# Fix file permissions:
 +
#: <source lang="bash">sudo chown -R <your-name>.<your-name> /usr/local/angstrom/arm</source>
 +
# Install the toolchain:
 +
#: <source lang="bash">$ bash /usr/local/angstrom/arm/scripts/installer.sh</source>
 +
# Download updated [http://sebt3.openpandora.org/buildtools/?f=genpxml genpxml] script and overwrite old one:
 +
#: <source lang="bash">$ mv genpxml /usr/local/angstrom/arm/scripts/genpxml</source>
 +
# Update the libraries to the lastest status :
 +
<source lang="bash">$ setprj
 +
$ opkg-target update
 +
$ opkg-target upgrade #(will be long, might need a few runs too)
 +
$ $SDK_PATH/scripts/installer.sh -only update_libtool
 +
$ $SDK_PATH/scripts/installer.sh -only update_config_script</source>
  
Alternatively you could try the easy to set up environment described on [http://blogs.distant-earth.com/wp/?p=109 DJWillis' blog] which is suitable for 32bit Linux. The process is explained, and corrected slightly (for Debian Squeeze systems), below.
+
=== Common Errors ===
 +
==== No such libmpfr.so.1 ====
 +
If you get the following error message while trying to compile projects:
 +
error while loading shared libraries: libmpfr.so.1: cannot open shared object file: No such file or directory
 +
You can fix that by commenting out the following lines of the "environment-setup" file:
 +
# if [ ! -e "/usr/lib/libgmp.so.3" ] || [ ! -e "/usr/lib/libmpfr.so.1" ];then
 +
(...and 7 lines later...)
 +
#fi
  
=== DJWillis' Cross Compiler, Redux ===
+
== DJWillis's Cross Compiler ==
 +
You could try the easy-to-setup environment described on [http://blogs.distant-earth.com/wp/?p=109 DJWillis' blog] 2010 which is suitable for 32bit Linux.  However, the process is also expanded further below.
  
 
DJ-Willis's cross-compiling toolchain page is really awesome, but it has a few holes I'd like to patch up in this guide.  Here, we'll be creating a chroot jail to install the toolchain on with a Debian Squeeze system.  This will allow you to use DJ Willis's toolchain without mucking with your normal system at all.  Of course, it's obviously overkill, but, hey, what's technical insight without it?
 
DJ-Willis's cross-compiling toolchain page is really awesome, but it has a few holes I'd like to patch up in this guide.  Here, we'll be creating a chroot jail to install the toolchain on with a Debian Squeeze system.  This will allow you to use DJ Willis's toolchain without mucking with your normal system at all.  Of course, it's obviously overkill, but, hey, what's technical insight without it?
Line 13: Line 64:
 
The commands are detailed exactly as you'll need to enter them, from start to finish, to compile Pandora native apps on your host system. They'll run really well on the Pandora, but they won't run on your host.  To do that, you'll need to compile them for the host system, which is a different, but much simpler, process.
 
The commands are detailed exactly as you'll need to enter them, from start to finish, to compile Pandora native apps on your host system. They'll run really well on the Pandora, but they won't run on your host.  To do that, you'll need to compile them for the host system, which is a different, but much simpler, process.
  
==== Resources ====
+
=== Resources ===
 
 
 
The following are generic resources you might want to read up on to make better sense of the instructions that follow.
 
The following are generic resources you might want to read up on to make better sense of the instructions that follow.
  
Line 22: Line 72:
 
* http://pandorapress.net/2009/03/11/so-you-want-to-try-angstrom/
 
* http://pandorapress.net/2009/03/11/so-you-want-to-try-angstrom/
  
==== Instructions ====
+
=== Instructions ===
 
 
 
The following instructions are for a (Debian) host system that you have root access to.  The system-inside-a-system you're building will probably take about 1 GiB of hard-drive space.
 
The following instructions are for a (Debian) host system that you have root access to.  The system-inside-a-system you're building will probably take about 1 GiB of hard-drive space.
  
$ cd ~  
+
<source lang="bash">
$ mkdir pandora_cross_compiler
+
cd ~  
$ su -c "apt-get install debootstrap chroot" # get the dependencies
+
mkdir pandora_cross_compiler
$ su -c "debootstrap squeeze pandora_cross_compiler" # see the debootstrap wiki
+
su -c "apt-get install debootstrap chroot" # get the dependencies
$ su -c "LANG=C chroot pandora_cross_compiler /bin/bash" # see the chroot wiki
+
su -c "debootstrap --arch=i386 squeeze pandora_cross_compiler" # see the debootstrap wiki
# apt-get install bzip2 unzip curl libmpfr-dev
+
su -c "LANG=C chroot pandora_cross_compiler /bin/bash" # see the chroot wiki
# ln -s /usr/lib/libmpfr.so /usr/lib/libmpfr.so.1
+
apt-get install bzip2 unzip curl libmpfr-dev
# cd ~
+
ln -s /usr/lib/libmpfr.so /usr/lib/libmpfr.so.1
# wget http://djwillis.openpandora.org/toolchains/20100611-i686-linux-armv7a-linux-gnueabi-toolchain-openpandora.tar.bz2 http://djwillis.openpandora.org/toolchains/DisplayImage.zip
+
cd ~
# tar -C / -xjf 20100611-i686-linux-armv7a-linux-gnueabi-toolchain-openpandora.tar.bz2
+
wget http://djwillis.openpandora.org/toolchains/20100611-i686-linux-armv7a-linux-gnueabi-toolchain-openpandora.tar.bz2 http://djwillis.openpandora.org/toolchains/DisplayImage.zip
# unzip DisplayImage.zip
+
tar -C / -xjf 20100611-i686-linux-armv7a-linux-gnueabi-toolchain-openpandora.tar.bz2
# . /usr/local/angstrom/arm/environment-setup
+
unzip DisplayImage.zip
# arm-angstrom-linux-gnueabi-gcc -Wall DisplayImage.c -o DisplayImage -l SDL
+
. /usr/local/angstrom/arm/environment-setup
# exit
+
arm-angstrom-linux-gnueabi-gcc -Wall DisplayImage.c -o DisplayImage -l SDL
 +
exit
 +
</source>
  
 
Congratulations!  You just compiled an ARM-based executable!  It won't run on the Intel 32-bit system you're testing it on!  To see it not run on your normal system, run:
 
Congratulations!  You just compiled an ARM-based executable!  It won't run on the Intel 32-bit system you're testing it on!  To see it not run on your normal system, run:
 +
<source lang="bash">
 +
su -c "cp pandora_cross_compiler/root/DisplayImage .; cp pandora_cross_compiler/root/test.bmp ."
 +
su -c "chown (your user):(your group) DisplayImage test.bmp"
 +
./DisplayImage
 +
</source>
  
$ su -c "cp pandora_cross_compiler/root/DisplayImage .; cp pandora_cross_compiler/root/test.bmp ."
+
You compiled it for the Pandora.  If you have a Pandora, copy it to the Pandora and it should work.
$ su -c "chown (your user):(your group) DisplayImage test.bmp"
 
$ ./DisplayImage
 
 
 
It won't work.  It's not supposed to work.  You compiled it for the Pandora.  If you have a Pandora, copy it to the Pandora and it should work.
 
  
 
To get back into your chroot jail to compile more programs that you can copy then back into your normal system and your Pandora, you'll just need to run:
 
To get back into your chroot jail to compile more programs that you can copy then back into your normal system and your Pandora, you'll just need to run:
  
$ su -c "LANG=C chroot pandora_cross_compiler /bin/bash"
+
<source lang="bash">su -c "LANG=C chroot pandora_cross_compiler /bin/bash</source>
  
 
And Bam!  You're back in the chroot.
 
And Bam!  You're back in the chroot.
  
 
Consider using QEmu to create an ARM VM for testing the programs.  See the Pandora Press link for those instructions.  Also see the comments for getting the QEmu image to run in Linux.
 
Consider using QEmu to create an ARM VM for testing the programs.  See the Pandora Press link for those instructions.  Also see the comments for getting the QEmu image to run in Linux.
 +
 +
 +
== Using the SDK-Installer ==
 +
Cpasjuste on the GP32X forums has made a nice script to get a build environment and libraries installed on Ubuntu/Debian systems. Download links and a brief explanation can be found in [http://www.gp32x.com/board/index.php?/topic/52343-pandora-sdk-installer/ this thread].
 +
 +
A new approach at creating a crosscompiler toolchain was done by Ivanovic. It is based previous codesourcery toolchain attempts but uses the packages that openpandora relies on, too. It should work for every Linux system that can make use of x86 binaries (meaning x86 systems as well as amd64 systems with multilib support). A more detailed explanation of the SDK as well as the scripts required to install it are available in [http://boards.openpandora.org/index.php?/topic/7147-crosscompiler-toolchain-based-on-openpandoraorg-ipks/ this thread].
 +
  
 
== Manual Installation ==
 
== Manual Installation ==
 
 
If you want a bit more control, Code-Sourcery hosts a bunch of cross-compiling suites for various platforms on their site, some editions have to be paid for, but they do have "lite" editions without support that are completely free.
 
If you want a bit more control, Code-Sourcery hosts a bunch of cross-compiling suites for various platforms on their site, some editions have to be paid for, but they do have "lite" editions without support that are completely free.
  
Line 65: Line 123:
 
Installers are available for Linux and Windows. Alternatively, download and unpack the tarball, then add the bin directory to your path.
 
Installers are available for Linux and Windows. Alternatively, download and unpack the tarball, then add the bin directory to your path.
  
== Example: Setting up a cross compiler using Code Sourcery, and doing so inside a VM ==
+
=== Example: Setting up a cross compiler using Code Sourcery, and doing so inside a VM ===
 +
Skeezix makes some notes in [http://fw.skeleton.org/~jeff/blog2009/2010/06/02/getting-up-and-going-with-a-crosscompiler-for-pandora-arm-in-5-minutes/ his blog] about setting up CodeSourcery's prebuilt toolchain in a VM very quickly.
 +
 
 +
 
 +
== Possible Problems ==
 +
If you get an error when compiling along of the lines of "error while loading shared libraries: libmpfr.so.1: cannot open shared object file: No such file or directory", run
 +
<source lang="bash">apt-get install libmpfr1ldbl</source> and attempt to compile again.
  
Skeezix makes some notes in [http://www.rjmitchell.ca/~jeff/blog2009/2010/06/02/getting-up-and-going-with-a-crosscompiler-for-pandora-arm-in-5-minutes/ his blog] about setting up CodeSourcery's prebuilt toolchain in a VM very quickly.
 
  
 
[[Category:Development]]
 
[[Category:Development]]
 +
[[Category:Tutorials]]

Latest revision as of 17:54, 29 January 2015

One of the ways to compile your applications to the ARM architecture is through a cross-compiler. This will allow you to compile applications for the ARM architecture on a different system. This is good if you want to develop for the Pandora but are still waiting to receive it, or if you have an application that takes too much memory or drive-space to effectively compile on the Pandora itself. At the moment, there are 4 different ways you can set up a cross compiling environment.

These options are sorted in order of preference. Option two is preferred over three, etc.

A native compilation solution (with optionally distcc)

http://cloudef.pw/pandora/dchrt/

Instructions: here 2013

The chroot and most of the tools are by urjaman, some of the ipk's and mirroring/hosting by Cloudef.

< Cloudef> urjaman: make it "Obvious solution for elitists"

Ivanovic's CodeSourcery-Based Cross Compiler



This toolchain is based on previous codesourcery toolchain attempts but uses the packages that openpandora relies on. It should work for every Linux system that can make use of x86 binaries (meaning x86 systems as well as amd64 systems with multilib support). A detailed explanation of the SDK as well as the script required to install it are available in this forum thread. 2012

Notes:

  • This toolchain works on a 64-bit system, assuming 32-bit compatibility libraries are installed. On Debian, they can be installed with:
aptitude install ia32-libs-dev


Sebt3's Yactfeau

http://www.gp32x.com/board/index.php?/topic/58490-yactfeau/ 2011 Notes:

  • This toolchain works on a 64-bit system, assuming 32-bit compatibility libraries are installed. On Debian, they can be installed with:
aptitude install ia32-libs-dev

Using the Toolchain

  1. If you don't already have a Linux-based system you want to use, download and run the Pandora VirtualBox Image.
  2. Remove your previous installation by running (default password is devel):
    sudo rm -rf /usr/local/angstrom/arm/*
    
  3. Download the toolchain (torrent).
  4. Unpack the toolchain:
    sudo tar -C /usr/local/angstrom/arm -xjf pandora-toolchain-20110313.tar.bz2
    
  5. Fix file permissions:
    sudo chown -R <your-name>.<your-name> /usr/local/angstrom/arm
    
  6. Install the toolchain:
    $ bash /usr/local/angstrom/arm/scripts/installer.sh
    
  7. Download updated genpxml script and overwrite old one:
    $ mv genpxml /usr/local/angstrom/arm/scripts/genpxml
    
  8. Update the libraries to the lastest status :
$ setprj
$ opkg-target update
$ opkg-target upgrade #(will be long, might need a few runs too)
$ $SDK_PATH/scripts/installer.sh -only update_libtool
$ $SDK_PATH/scripts/installer.sh -only update_config_script

Common Errors

No such libmpfr.so.1

If you get the following error message while trying to compile projects:

error while loading shared libraries: libmpfr.so.1: cannot open shared object file: No such file or directory

You can fix that by commenting out the following lines of the "environment-setup" file:

# if [ ! -e "/usr/lib/libgmp.so.3" ] || [ ! -e "/usr/lib/libmpfr.so.1" ];then
(...and 7 lines later...)
#fi

DJWillis's Cross Compiler

You could try the easy-to-setup environment described on DJWillis' blog 2010 which is suitable for 32bit Linux. However, the process is also expanded further below.

DJ-Willis's cross-compiling toolchain page is really awesome, but it has a few holes I'd like to patch up in this guide. Here, we'll be creating a chroot jail to install the toolchain on with a Debian Squeeze system. This will allow you to use DJ Willis's toolchain without mucking with your normal system at all. Of course, it's obviously overkill, but, hey, what's technical insight without it?

The commands are detailed exactly as you'll need to enter them, from start to finish, to compile Pandora native apps on your host system. They'll run really well on the Pandora, but they won't run on your host. To do that, you'll need to compile them for the host system, which is a different, but much simpler, process.

Resources

The following are generic resources you might want to read up on to make better sense of the instructions that follow.

Instructions

The following instructions are for a (Debian) host system that you have root access to. The system-inside-a-system you're building will probably take about 1 GiB of hard-drive space.

cd ~ 
mkdir pandora_cross_compiler
su -c "apt-get install debootstrap chroot" # get the dependencies
su -c "debootstrap --arch=i386 squeeze pandora_cross_compiler" # see the debootstrap wiki
su -c "LANG=C chroot pandora_cross_compiler /bin/bash" # see the chroot wiki
apt-get install bzip2 unzip curl libmpfr-dev
ln -s /usr/lib/libmpfr.so /usr/lib/libmpfr.so.1
cd ~
wget http://djwillis.openpandora.org/toolchains/20100611-i686-linux-armv7a-linux-gnueabi-toolchain-openpandora.tar.bz2 http://djwillis.openpandora.org/toolchains/DisplayImage.zip
tar -C / -xjf 20100611-i686-linux-armv7a-linux-gnueabi-toolchain-openpandora.tar.bz2
unzip DisplayImage.zip
. /usr/local/angstrom/arm/environment-setup
arm-angstrom-linux-gnueabi-gcc -Wall DisplayImage.c -o DisplayImage -l SDL
exit

Congratulations! You just compiled an ARM-based executable! It won't run on the Intel 32-bit system you're testing it on! To see it not run on your normal system, run:

su -c "cp pandora_cross_compiler/root/DisplayImage .; cp pandora_cross_compiler/root/test.bmp ."
su -c "chown (your user):(your group) DisplayImage test.bmp"
./DisplayImage

You compiled it for the Pandora. If you have a Pandora, copy it to the Pandora and it should work.

To get back into your chroot jail to compile more programs that you can copy then back into your normal system and your Pandora, you'll just need to run:

su -c "LANG=C chroot pandora_cross_compiler /bin/bash

And Bam! You're back in the chroot.

Consider using QEmu to create an ARM VM for testing the programs. See the Pandora Press link for those instructions. Also see the comments for getting the QEmu image to run in Linux.


Using the SDK-Installer

Cpasjuste on the GP32X forums has made a nice script to get a build environment and libraries installed on Ubuntu/Debian systems. Download links and a brief explanation can be found in this thread.

A new approach at creating a crosscompiler toolchain was done by Ivanovic. It is based previous codesourcery toolchain attempts but uses the packages that openpandora relies on, too. It should work for every Linux system that can make use of x86 binaries (meaning x86 systems as well as amd64 systems with multilib support). A more detailed explanation of the SDK as well as the scripts required to install it are available in this thread.


Manual Installation

If you want a bit more control, Code-Sourcery hosts a bunch of cross-compiling suites for various platforms on their site, some editions have to be paid for, but they do have "lite" editions without support that are completely free.

Head up onto here. The recommended release at time of writing is 2009q3.

Installers are available for Linux and Windows. Alternatively, download and unpack the tarball, then add the bin directory to your path.

Example: Setting up a cross compiler using Code Sourcery, and doing so inside a VM

Skeezix makes some notes in his blog about setting up CodeSourcery's prebuilt toolchain in a VM very quickly.


Possible Problems

If you get an error when compiling along of the lines of "error while loading shared libraries: libmpfr.so.1: cannot open shared object file: No such file or directory", run

apt-get install libmpfr1ldbl

and attempt to compile again.