In my previous post, I discussed the woes of compiling code on the Raspberry Pi. The Raspberry Pi is not very fast which adds an additional amount of tedium to the prospect of doing any projects related to the Raspberry Pi. After I did some brief research, I found that crosstool-ngwas a great tool which would enable me to create a toolchain with all the features I needed. Additionally, with crosstool-ng you can practically build any toolchain for any target platform! (sweet!) More information about my process and a link to a pre-built toolchain after the break!
If you are unfamiliar with the process of compiling a toolchain on your own computer, let me be frank: it’s not fun. Luckily, with a combination of past experience and help from others on the web. Ultimately, my success though can be attributed to those people who have developed the tools or who have previously gone though the process. Without them, this guide would not be here!
So without further adieu lets do this thing.
Fully built binaries can be found here.
These files include:
Based on Linux Kernel “3.10.2”
You will need Hombrew to install some dependencies. If you haven’t already installed it you can run the command below:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Note: a few other dependencies get installed when crosstool-ng is compiled. Be prepared to wait a little while everything assembles.
brew install crosstool-ng
Note: this is more of a precaution then a requirement. I believe by the end of this process that this was not necessary for getting crosstool-ng to work.
brew install gettext
Open up Disk utility. Click on the New Image button.
1. You need a disk at least 5GB in size. This will house all the source code and object files when all said and done.
2. The next disk can be exactly the same but only 250MB in size. (When fully compiled and compressed everything turned out to be around 107MB)
Crosstools relies on the use of GNU grep. The grep built with OSX is not 100% exactly the same. So, let’s build it!
brew tap homebrew/dupes
brew install grep --default-names
My paths.sh file was located here:
/usr/local/Cellar/crosstool-ng/1.19.0/lib/ct-ng.1.19.0
I changed the grep line from:
export grep="/usr/bin/grep"
To:
export grep="/usr/local/bin/grep"
This will load a general Linux/GNU config. We’ll end up replacing the config but it gives us a good starting point.
ct-ng arm-unknown-linux-gnueabi
Download the config file here.
You will have to copy it to your case sensitive disk image and rename it to .config.
Run the following in your working directory.
ct-ng menuconfig
Change the following as needed
Note: all of these are under the ** Paths ** section.
Local tarballs directory
I used /Volumes/xtools-build-env/src. Make sure you set yours to your setup.
/Volumes/{your case sensitive disk image here}/src
Working directory
I used /Volumes/xtools-build-env/.build. Make sure you set yours to your setup.
/Volumes/{your case sensitive disk image here}/.build
Prefix directory
I used /Volumes/xtools/${CT_TARGET}. Make sure you set yours to your setup.
/Volumes/{your smaller case sensitive disk image here}/${CT_TARGET}
Note: the next few settings are under the ** Extracting ** section.
Stop after extracting tarballs
This option should be checked.
Parallel jobs
Edit the number of parallel jobs. Just multiply the number of cores you have times two.
Run the following command:
ct-ng build
The build command will stop after extracting all the sources.
Locate the Makefile.in in /Volumes/{your case sensitive image}/.build/src/gcc-linaro-4.8-2013.06-1/gcc
Note: this error only seems to happen when you are parallel building.
Apply the following patch:
--- Makefile.in 2014-02-06 17:34:12.000000000 -0800
+++ Makefile_new.in 2014-02-06 17:34:23.000000000 -0800
@@ -3801,7 +3801,7 @@
$(STAMP) s-gtype
generated_files = config.h tm.h $(TM_P_H) $(TM_H) multilib.h \
- $(simple_generated_h) specs.h \
+ $(simple_generated_h) specs.h insn-opinit.h \
tree-check.h genrtl.h insn-modes.h tm-preds.h tm-constrs.h \
$(ALL_GTFILES_H) gtype-desc.c gtype-desc.h gcov-iov.h
Download the patch here.
(help from http://patchwork.ozlabs.org/patch/254725/)
Locate type.h in /Volumes/{your case sensitive image}/.build/src/eglibc-2_17/sunrpc/rpc
--- types.h 2014-02-06 17:40:13.000000000 -0800
+++ types_new.h 2014-02-06 17:38:22.000000000 -0800
@@ -69,6 +69,9 @@
#include
#endif
+/* The system headers on Mac OS X conflict with these typedefs */
+#ifndef __APPLE__
+# error Error: should not be here if compiling under OSX.
#ifndef __u_char_defined
typedef __u_char u_char;
typedef __u_short u_short;
@@ -84,6 +87,7 @@
typedef __caddr_t caddr_t;
# define __daddr_t_defined
#endif
+#endif
#include
#include
Credit goes to UnhandledException for this patch.
ulimit -n 1024
Ulimit controls the amount of resources allowed by a shell instance. In this case we need to increase this limit in order to prevent compilation errors.
Undo one of the config settings we changed earlier. Open up:
ct-ng menuconfig
Note: the next few settings are under the ** Extracting ** section.
Stop after extracting tarballs
This option should be unchecked.
Run:
ct-ng build
Depending on how fast your setup is it may take a few hours to compile fully. If you’re impatient you can always get the binaries I just compiled here
By the time it’s done doing its thing you should have a fully capable cross platform toolchain for the Raspberry Pi! (Woot) An easy way to test it is to do the following:
cat > test.c
#include
int main() { printf("Hello, world!\n"); return 0; }
(Hit ctrl-d to escape)
/Volumes/{path to smaller case-sensitive disk image}/arm-unknown-linux-gnueabi-gcc -o test test.c
Copy test over to your Raspberry Pi.
rsync -rtzh --delete test pi@raspberrypi:/home/pi
Then ssh in and run the test executable
ssh pi@raspberrypi '/home/pi/test'
I have recieved a few notes from others who have had some other issues compiling. I will post them here:
[ERROR] configure.in:294: error: automatic de-ANSI-fication support
has been removed
Which turned out to be from an older version of MPFR (soft float
stuff). I got it working by configuring the toolchain for the version
I had installed (3.1.2), in Companion Libraries -> MPFR version.
Thanks to Heewa B. for info!
I used several blog posts and articles over the web to get this to work. Many thanks to their previous efforts.
Want more Raspberry Pi Posts? Check our more posts below!
from http://www.jaredwolff.com/blog/cross-compiling-on-mac-osx-for-raspberry-pi/