Lots of info about Cross-Compiler can be found here http://wiki.osdev.org/GCC_Cross-Compiler
So lets start with building the toolchain for building Raspberry Pi applications with crosstool-ng and the GNU Compiler.
Preperations
In order to compile crosstool-ng we need to install some packages in cygwin first. Run setup.exe and install the following packages
gcc
make
bison
flex
gperf
patch
libtool
libncurses-devel
ca-certificates
wget
crosstool-ng
Installing on cygwin
The installation of crosstool-ng is a little bit tricky on cygwin, since some customization is needed. The needed steps needed are summarized below, but basicly its strait forward download, unpack, patch, build and install.
cd /usr/src wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.18.0.tar.bz2 tar jxf crosstool-ng-1.18.0.tar.bz2 cd crosstool-ng-1.18.0 # -R is added because patch complained. Maybe I created the patch wrongly patch -p1 -R -i ../crosstool-ng_cygwin.patch ./configure make && make install
Done. The patch can be downloaded or just copy and paste the following into a file.
diff -rupN crosstool-ng-1.18.0.old/kconfig/Makefile crosstool-ng-1.18.0/kconfig/Makefile --- crosstool-ng-1.18.0.old/kconfig/Makefile 2013-01-31 21:07:52.000000000 +0100 +++ crosstool-ng-1.18.0/kconfig/Makefile 2013-07-02 19:02:07.990701900 +0200 @@ -35,20 +35,21 @@ conf_SRC = conf.c conf_OBJ = $(patsubst %.c,%.o,$(conf_SRC)) conf_DEP = $(patsubst %.o,%.dep,$(conf_OBJ)) $(conf_OBJ) $(conf_DEP): CFLAGS += $(INTL_CFLAGS) +conf: LDFLAGS += -lintl # What's needed to build 'mconf' mconf_SRC = mconf.c mconf_OBJ = $(patsubst %.c,%.o,$(mconf_SRC)) mconf_DEP = $(patsubst %.c,%.dep,$(mconf_SRC)) $(mconf_OBJ) $(mconf_DEP): CFLAGS += $(NCURSES_CFLAGS) $(INTL_CFLAGS) -mconf: LDFLAGS += $(NCURSES_LDFLAGS) +mconf: LDFLAGS += $(NCURSES_LDFLAGS) -lintl # What's needed to build 'nconf' nconf_SRC = nconf.c nconf.gui.c nconf_OBJ = $(patsubst %.c,%.o,$(nconf_SRC)) nconf_DEP = $(patsubst %.c,%.dep,$(nconf_SRC)) $(nconf_OBJ) $(nconf_DEP): CFLAGS += $(INTL_CFLAGS) -I/usr/include/ncurses -nconf: LDFLAGS += -lmenu -lpanel -lncurses +nconf: LDFLAGS += -lmenu -lpanel -lncurses -lintl # Under Cygwin, we need to auto-import some libs (which ones, exactly?) # for mconf and nconf to lin properly. diff -rupN crosstool-ng-1.18.0.old/kconfig/nconf.c crosstool-ng-1.18.0/kconfig/nconf.c --- crosstool-ng-1.18.0.old/kconfig/nconf.c 2013-01-31 21:07:52.000000000 +0100 +++ crosstool-ng-1.18.0/kconfig/nconf.c 2013-07-02 19:02:07.994701500 +0200 @@ -1518,7 +1518,7 @@ int main(int ac, char **av) } notimeout(stdscr, FALSE); - ESCDELAY = 1; + set_escdelay(1); /* set btns menu */ curses_menu = new_menu(curses_menu_items);
At last we have to make the file system case sensitive or otherwise the compilation of the toolchain will fail. To do so you can download the patch or run regedit.exe and got to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Kernel and change obcaseinsensitive to 0.
Setting up Toolchain for Raspberry
Now the part, where we actually build the toolchain for the Raspberry Pi in cygwin change to your home dir by typing cd in the cygwin command promt. From the Raspberry Pi Tools we download the configuration file for crosstool-ng namely bcm2708hardfp-ct-ng.config. My modified config file can be found here.
wget https://raw.github.com/raspberrypi/tools/master/configs/bcm2708hardfp-ct-ng.config cp bcm2708hardfp-ct-ng.config .config ct-ng menuconfig
Now check if all setting are right. I used the liano gcc 4.7 which works just fine and lets kick it off
ct-ng build
After a long coffee break we can start testing if the toolchain is working as expected. Before we should add the toolchain to our path by editing ~/.bashrc and adding
export PATH=~/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin:$PATH
Most of my info was taken from these sites
http://www.kitware.com/blog/home/post/426
https://github.com/raspberrypi/tools/
http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/
http://archlinuxarm.org/developers/distcc-cross-compiling
http://raspberrypi.stackexchange.com/questions/1/how-do-i-build-a-gcc-4-7-toolchain-for-cross-compiling
Testing the Toolchain
Now that we have our Toolchain all setup to compile applications for the Raspberry Pi we should test if it works. So let compile some applications and test them on the Raspberry Pi.
#include <stdio.h> int main() { printf("Hello, world!\n"); return 0; }
#include <iostream> int main() { std::cout << "Hello World++ !" << std::endl; return 0; }
and compile them
arm-bcm2708hardfp-linux-gnueabi-gcc hello_world.c -o helloworld arm-bcm2708hardfp-linux-gnueabi-g++ hello_world.c++ -o helloworld++
Now lets transfer them to the Raspberry Pi and run’em. In my case it worked just fine
Troubleshooting
Running applications
I read that it might come to troubles when you compile with a different Version of a compiler version than the host system has. For now I will use the latest compiler version that I can. If problems arise we should switch to the same compiler version as the host system.
cygwin SSL Certificate Error
ct-ng build always stopped when it tried to retrieve the kernel.
[ALL ] ERROR: The certificate of `www.kernel.org‘ is not trusted.
[ALL ] ERROR: The certificate of `www.kernel.org‘ hasn’t got a known issuer.
This is fixed by doing ln -s /usr/ssl /etc/ssl. Done.
[…] そもそも、crosstool-ng は http://crosstool-ng.org/ で入手できます。 これを cygwin で使用するためには以下のパッチを適用します。このパッチはここで紹介されていましたが、パッチファイルがダウンロードできないようだったので、ここにテキストとして貼り付けておきます。 […]