Cross compiling for Raspberry Pi in Windows 8

Lots of info about Cross-Compiler can be found here

So lets start with building the toolchain for building Raspberry Pi applications with crosstool-ng and the GNU Compiler.


In order to compile crosstool-ng we need to install some packages in cygwin first. Run setup.exe and install the following packages



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
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
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) -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);
+	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.

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

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


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 `‘ is not trusted.
[ALL  ]    ERROR: The certificate of `‘ hasn’t got a known issuer.

This is fixed by doing ln -s /usr/ssl /etc/ssl. Done.

1 Comment

  1. […] そもそも、crosstool-ng は で入手できます。 これを cygwin で使用するためには以下のパッチを適用します。このパッチはここで紹介されていましたが、パッチファイルがダウンロードできないようだったので、ここにテキストとして貼り付けておきます。 […]

Schreibe einen Kommentar