How would i go about setting up a cross compiling toolchain for the pi?
giving a host of 64bit ubuntu or debian
Re: Cross compiling?
Take a look here:
http://elinux.org/RPi_Kernel_Compilation#Ubuntu_Linux
I have 64-bit 12.04 Ubuntu, and it worked as per the instructions.
http://elinux.org/RPi_Kernel_Compilation#Ubuntu_Linux
I have 64-bit 12.04 Ubuntu, and it worked as per the instructions.
Re: Cross compiling?
Forgive my ignorance, but are those the steps to setup cross-compilation from a different platform to the ARM of the RPi?
If so, following the last step, does one simply compile with gcc and the output is then ARM-based?
If so, following the last step, does one simply compile with gcc and the output is then ARM-based?
Re: Cross compiling?
It gets you a few steps closer. Once you follow the steps to install the cross compiler for your desktop's distro you should have a compiler along the lines of: /usr/bin/arm-unknown-linux-gnueabi-gcc or /opt/local/bin/arm-unknown-linux-gnueabi-gcc
So to make this simpler we'll just make a little hello world program.
We can compile it natively via:
The file command shows us that the file is built for a 64-bit x86-64 Linux system. If we want to cross compile this file we would change the compiler we call:
Now if you copy that file onto your Pi you can run it and get the printout we saw in the native build. If you are looking to build an entire project you'll want to look into how to run their build scripts using cross compilers.
So to make this simpler we'll just make a little hello world program.
Code: Select all
#include <stdio.h>
int main ()
{
printf("Hello Cross Compiled Pi\n");
return 0;
}
Code: Select all
# gcc -o native-hello hello.c
# file native-hello
native-hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
# ./native-hello
Hello Cross Compiled Pi
#
Code: Select all
# arm-unknown-linux-gnueabi-gcc -o arm-hello hello.c
# file arm-hello
arm-hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.27, not stripped
#
xmpp: [email protected]
Blog: http://jecxjo.motd.org/code
Blog: http://jecxjo.motd.org/code
- johnbeetem
- Posts: 945
- Joined: Mon Oct 17, 2011 11:18 pm
- Location: The Mountains
Re: Cross compiling?
You can also get the CodeSourcery G++ Lite port of GCC: here's a wiki page, targeted primarily at BeagleBoard: http://www.elinux.org/ARMCompilers. I've successfully used version "2011.03-41 for ARM GNU/Linux" on 32-bit Ubuntu 11.10.
Re: Cross compiling?
When you install this tool chain does it also get all the standard libs for the system too?
Am I correct in thinking for doing RPi specifics like GLES all I have to do then is copy the folder from /etc/vc to my build PC and include that in the normal way in my make files?
Am I correct in thinking for doing RPi specifics like GLES all I have to do then is copy the folder from /etc/vc to my build PC and include that in the normal way in my make files?
Re: Cross compiling?
Hello - I am following the work flows to cross compile the raspberry kernel. However, I have not been able to get any arm executable to run on the pi.
My goal is to Cross Compile the full Linux Kernel adding new modules using make menuconfig
The basics of getting my tool chain right.
Some details (hoping this might help other debug the same issues) :
Host Machine Running Ubuntu 12.04 LTE with all latest updates.
Linux 3.2.0-24-generic-pae #39-Ubuntu SMP Mon May 21 18:54:21 UTC 2012 i686 athlon i386 GNU/Linux
Pi
Linux raspberrypi 3.1.9+ #90 Wed Apr 18 18:23:05 BST 2012 armv6l GNU/Linux
Toolchain - as described in http://elinux.org/RPi_Kernel_Compilation
- sudo apt-get install gcc-4.6-arm-linux-gnueabi
I can compile all OK a simple Hello World program (as shown on this page) using the standard gcc on Ubuntu 12.04. This runs all OK and outputs the right stuff.
I then use the cross compile to compile for Pi. No errors.
I copy the output to the platform and run the executable and then get a Segmentation Fault.
Looking at the file using >file ./a.out
./a.out: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, not stripped
Can anyone see anything wrong ?
Note - I also do File /bin/ls and see :-
/bin/ls: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
Could the issue be the version of Linux that is build for is higher in version
Look forward to any advise out there...
Ian
My goal is to Cross Compile the full Linux Kernel adding new modules using make menuconfig
The basics of getting my tool chain right.
Some details (hoping this might help other debug the same issues) :
Host Machine Running Ubuntu 12.04 LTE with all latest updates.
Linux 3.2.0-24-generic-pae #39-Ubuntu SMP Mon May 21 18:54:21 UTC 2012 i686 athlon i386 GNU/Linux
Pi
Linux raspberrypi 3.1.9+ #90 Wed Apr 18 18:23:05 BST 2012 armv6l GNU/Linux
Toolchain - as described in http://elinux.org/RPi_Kernel_Compilation
- sudo apt-get install gcc-4.6-arm-linux-gnueabi
I can compile all OK a simple Hello World program (as shown on this page) using the standard gcc on Ubuntu 12.04. This runs all OK and outputs the right stuff.
I then use the cross compile to compile for Pi. No errors.
I copy the output to the platform and run the executable and then get a Segmentation Fault.
Looking at the file using >file ./a.out
./a.out: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, not stripped
Can anyone see anything wrong ?
Note - I also do File /bin/ls and see :-
/bin/ls: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
Could the issue be the version of Linux that is build for is higher in version
Look forward to any advise out there...
Ian
Re: Cross compiling?
I have this problem also.
I'm running on a Ubuntu 12.04 and I've followed the instructions on the building a kernel page,
but when I run a cross-compiled Hello World I get a Segmentation Fault.
I'm compiling under Ubuntu 12.04 as:
/usr/bin/arm-linux-gnueabi-gcc -o arm3.out HelloWorld.c
Running on the Pi gives:
$ ./arm.out
Segmentation fault
Running the program natively works fine.
Below is the output of strace on the cross-compiled executeable:
Any clue?
execve("./arm.out", ["./arm.out"], [/* 17 vars */]) = 0
brk(0) = 0x8f6000
uname({sys="Linux", node="raspberrypi", ...}) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400c8000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=41200, ...}) = 0
mmap2(NULL, 41200, PROT_READ, MAP_PRIVATE, 3, 0) = 0x4013a000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabi/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0XX\1\0004\0\0\0"..., 512) = 512
lseek(3, 1211164, SEEK_SET) = 1211164
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1400) = 1400
lseek(3, 1210724, SEEK_SET) = 1210724
read(3, "A'\0\0\0aeabi\0\1\35\0\0\0\0054T\0\6\2\10\1\t\1\22\4\24\1\25\1"..., 40) = 40
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4018b000
fstat64(3, {st_mode=S_IFREG|0755, st_size=1212564, ...}) = 0
mmap2(NULL, 1254688, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40287000
mprotect(0x403ad000, 28672, PROT_NONE) = 0
mmap2(0x403b4000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x125) = 0x403b4000
mmap2(0x403b7000, 9504, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x403b7000
close(3) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400ef000
set_tls(0x400ef4c0, 0x400efb97, 0x400efb98, 0x400ef4c0, 0x400d0000) = 0
mprotect(0x403b4000, 8192, PROT_READ) = 0
mprotect(0x10000, 4096, PROT_READ) = 0
mprotect(0x400cf000, 4096, PROT_READ) = 0
munmap(0x4013a000, 41200) = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
I'm running on a Ubuntu 12.04 and I've followed the instructions on the building a kernel page,
but when I run a cross-compiled Hello World I get a Segmentation Fault.
I'm compiling under Ubuntu 12.04 as:
/usr/bin/arm-linux-gnueabi-gcc -o arm3.out HelloWorld.c
Running on the Pi gives:
$ ./arm.out
Segmentation fault
Running the program natively works fine.
Below is the output of strace on the cross-compiled executeable:
Any clue?
execve("./arm.out", ["./arm.out"], [/* 17 vars */]) = 0
brk(0) = 0x8f6000
uname({sys="Linux", node="raspberrypi", ...}) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400c8000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=41200, ...}) = 0
mmap2(NULL, 41200, PROT_READ, MAP_PRIVATE, 3, 0) = 0x4013a000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabi/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0XX\1\0004\0\0\0"..., 512) = 512
lseek(3, 1211164, SEEK_SET) = 1211164
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1400) = 1400
lseek(3, 1210724, SEEK_SET) = 1210724
read(3, "A'\0\0\0aeabi\0\1\35\0\0\0\0054T\0\6\2\10\1\t\1\22\4\24\1\25\1"..., 40) = 40
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4018b000
fstat64(3, {st_mode=S_IFREG|0755, st_size=1212564, ...}) = 0
mmap2(NULL, 1254688, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40287000
mprotect(0x403ad000, 28672, PROT_NONE) = 0
mmap2(0x403b4000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x125) = 0x403b4000
mmap2(0x403b7000, 9504, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x403b7000
close(3) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400ef000
set_tls(0x400ef4c0, 0x400efb97, 0x400efb98, 0x400ef4c0, 0x400d0000) = 0
mprotect(0x403b4000, 8192, PROT_READ) = 0
mprotect(0x10000, 4096, PROT_READ) = 0
mprotect(0x400cf000, 4096, PROT_READ) = 0
munmap(0x4013a000, 41200) = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Re: Cross compiling?
... and file arm.out gives:
arm.out: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, BuildID[sha1]=0x7f7e5a58f994614441eb2aa813f571a09c1d1b82, not stripped
arm.out: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, BuildID[sha1]=0x7f7e5a58f994614441eb2aa813f571a09c1d1b82, not stripped
Re: Cross compiling?
You might need more compiler flags to produce executables compatible with the Pi, probably something like: -mcpu=arm1176jzf-s -mfloat-abi=softmjbright wrote:I'm compiling under Ubuntu 12.04 as:
/usr/bin/arm-linux-gnueabi-gcc -o arm3.out HelloWorld.c
Easier to grab the arm-bcm2708-linux-gnueabi-gcc from github instead, which has the right flags by default: https://github.com/raspberrypi/tools
Re: Cross compiling?
Thanks a lot, I'm now using the arm-bcm2708-linux-gnueabi tools from github and that did the trick.
That said, I couldn't figure out how to use them, so searching around, I adapted what was written in this post:
http://blog.greg-net.co.uk/post/2122805 ... spberry-pi
So to build my hello world, I'm now using the following.
I'll see if I can put this in the Wiki.
export TOOL_PREFIX=$HOME/src/git/raspberrypi/tools/arm-bcm2708/linux-x86/bin/arm-bcm2708-linux-gnueabi
export CXX=$TOOL_PREFIX-g++
export AR=$TOOL_PREFIX-ar
export RANLIB=$TOOL_PREFIX-ranlib
export CC=$TOOL_PREFIX-gcc
export LD=$TOOL_PREFIX-ld
export CCFLAGS="-march=armv4 -mno-thumb-interwork"
$CC -o arm.out HelloWorld.c

That said, I couldn't figure out how to use them, so searching around, I adapted what was written in this post:
http://blog.greg-net.co.uk/post/2122805 ... spberry-pi
So to build my hello world, I'm now using the following.
I'll see if I can put this in the Wiki.
export TOOL_PREFIX=$HOME/src/git/raspberrypi/tools/arm-bcm2708/linux-x86/bin/arm-bcm2708-linux-gnueabi
export CXX=$TOOL_PREFIX-g++
export AR=$TOOL_PREFIX-ar
export RANLIB=$TOOL_PREFIX-ranlib
export CC=$TOOL_PREFIX-gcc
export LD=$TOOL_PREFIX-ld
export CCFLAGS="-march=armv4 -mno-thumb-interwork"
$CC -o arm.out HelloWorld.c
Re: Cross compiling?
The same way you were using gcc.mjbright wrote: That said, I couldn't figure out how to use them
/path-where-you-put-the-stuff/arm-bcm2708/linux-x86/bin/arm-bcm2708-linux-gnueabi-gcc -o executable HelloWorld.c
Setting variables like that can be useful if you want to compile existing projects using Makefiles, but is not necessary for single files.export TOOL_PREFIX=$HOME/src/git/raspberrypi/tools/arm-bcm2708/linux-x86/bin/arm-bcm2708-linux-gnueabi
export CXX=$TOOL_PREFIX-g++
export AR=$TOOL_PREFIX-ar
export RANLIB=$TOOL_PREFIX-ranlib
export CC=$TOOL_PREFIX-gcc
export LD=$TOOL_PREFIX-ld
export CCFLAGS="-march=armv4 -mno-thumb-interwork"
For simple cross compiling instructions, take a look at the manual Synology put together for people wanting to mod their NAS devices: http://download.synology.com/download/d ... _Guide.pdf
(just replace the "arm-marvell-linux-gnu" they do there with arm-bcm2708-linux-gnueabi)
Re: Cross compiling?
Hi,
For those who are still struggling to set up the cross compiler and/or executing generated binaries I'd suggest trying out biicode, its a tool that will donwnload and set up the cross-compilers for you also will send generated binaries directly to the raspberry pi
(Only works for ubuntu though)
For those who are still struggling to set up the cross compiler and/or executing generated binaries I'd suggest trying out biicode, its a tool that will donwnload and set up the cross-compilers for you also will send generated binaries directly to the raspberry pi

Re: Cross compiling?
Building your own cross-compiler from the ground up is not that difficult. What makes the process a burden is finding the right recipe, i.e. gcc, glibc, etc compatibilities. Also, make sure your machine has plenty of memory and processing power. You'd be surprised at how often the process breaks because of insufficient memory, 1 or 2 GB is not really enough.
The best book that I have read to get me going is Pro Linux Embedded Systems. The book can be hard to follow at times but is still a good resource.
The best book that I have read to get me going is Pro Linux Embedded Systems. The book can be hard to follow at times but is still a good resource.
Last edited by jhillix on Sun Jul 06, 2014 8:51 pm, edited 1 time in total.
- ShiftPlusOne
- Raspberry Pi Engineer & Forum Moderator
- Posts: 6460
- Joined: Fri Jul 29, 2011 5:36 pm
Re: Cross compiling?
My favourite cross-dev environment is this one. https://github.com/bmanojlovic/rpi-cross-compile
I've tried everything and that's the only one that just works without wasting your time.
I've tried everything and that's the only one that just works without wasting your time.
Re: Cross compiling?
I have started to put together a wiki with my How To documents. It's still in the infancy stage and might have some copy & paste errors 8D But feel free to have a look:
https://how-to-build-for-arm.wikispaces.com/
https://how-to-build-for-arm.wikispaces.com/
Re: Cross compiling?
I got the same problem with a simple "hello world" program. I built the program on Ubuntu x86 and transferred to the PI2 target using Filezilla ftp client.
After some minutes spent panicking ... eventually I checked the md5 of local executable and md5 on PI2 and ... bingo, they were different.
That stupid ftp client was "auto" choosing the transfer mode (ascii or binary), for some reason it was using ASCII to transfer my executable.
After some minutes spent panicking ... eventually I checked the md5 of local executable and md5 on PI2 and ... bingo, they were different.
That stupid ftp client was "auto" choosing the transfer mode (ascii or binary), for some reason it was using ASCII to transfer my executable.
Re: Cross compiling?
There is my step-by-step guide and some theoretical backgrounds for cross compiler: http://rpilinuxdev.blogspot.ro/
I used this to compile quite complex stuff like GStreamer 1.4 and few media apps on RPI B+.
I used this to compile quite complex stuff like GStreamer 1.4 and few media apps on RPI B+.
-
- Posts: 4
- Joined: Wed Aug 03, 2016 4:27 am
Re: Cross compiling?
Unfortunately, that blog is invite onlyinforide wrote:There is my step-by-step guide and some theoretical backgrounds for cross compiler: http://rpilinuxdev.blogspot.ro/

Re: Cross compiling?
I have activated the blog.
Alternatively you might take a look here : https://github.com/ionutneicu/rpi-cross-scripts
Alternatively you might take a look here : https://github.com/ionutneicu/rpi-cross-scripts
Re: Cross compiling?
You can use this SDK to cross compile kernel, libraries and create a bootable SD image.
https://bitbucket.org/manuelleiva/rpisys
Basically to create a complete SD image you have to download the tool and run:
https://bitbucket.org/manuelleiva/rpisys
Basically to create a complete SD image you have to download the tool and run:
Code: Select all
# Configure board
./configure --board raspberry_pi_3/raspberry_pi_3.defs
# Build system
make
Create a bootable image
# Create SD image
make image-sd
Re: Cross compiling?
Revisiting old topic. After doing some research around the net, I decided to do platform which allows to build RPI binaries basically on any host OS. (Linux, macOS, Windows) Using Vagrant and VirtualBox. I use this to make RPI binaries without "polluting" the RPI with -dev libraries etc.
Someone might find this helpful:
https://github.com/djazo/rpi-builder
Someone might find this helpful:
https://github.com/djazo/rpi-builder