Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jvcleave/ed342fb2d41564bcdab6 to your computer and use it in GitHub Desktop.
Save jvcleave/ed342fb2d41564bcdab6 to your computer and use it in GitHub Desktop.
Instructions for building a Jessie VM to cross-compile openFrameworks 0.9 applications for the Raspberry Pi 1 (arm6)
#ON THE RPI (if you haven't downloaded openFrameworks)
cd
curl -O http://192.237.185.151/versions/nightly/of_v20151008_linuxarmv6l_nightly.tar.gz
mkdir openFrameworks
tar vxfz of_v20151008_linuxarmv6l_nightly.tar.gz -C openFrameworks --strip-components 1
cd /home/pi/openFrameworks/scripts/linux/debian
sudo ./install_dependencies.sh
#INSTALL SMB WITH / ACCESS
# https://gist.github.com/jvcleave/f41132324ca75c2268f9
#ON THE MAC:
#INSTALL VIRTUALBOX
#INSTALL DEBIAN 64BIT JESSIE
#http://gemmei.acc.umu.se/mirror/cdimage/release/8.2.0-live/amd64/iso-hybrid/debian-live-8.2.0-amd64-standard.iso
#Use Bridge Mode (allows access to local network without NAT)
#No Desktop Needed
#Give it at least 10GB storage
#ON THE DEBIAN VM:
#NOTE:BELOW INSTRUCTIONS USE pi AS DEBIAN USER
#ADD pi USER TO ROOT GROUP
#(via https://www.privateinternetaccess.com/forum/discussion/18063/debian-8-1-0-jessie-sudo-fix-not-installed-by-default)
su
apt-get install sudo
adduser pi sudo
nano /etc/sudoers
# under "User privilege specification" add pi line below to look like
# User privilege specification
root ALL=(ALL:ALL) ALL
pi ALL=(ALL:ALL) ALL
#INSTALL NEEDED PACKAGES
sudo apt-get install pkg-config make build-essential cifs-utils avahi-daemon avahi-utils libavahi-compat-libdnssd-dev
# MOUNT PI ON DEBIAN
sudo mkdir /media/Data
sudo nano /etc/fstab
#ADD LINE (raspberrypi.local is RPi Network address - can be IP)
//raspberrypi.local/Data /media/Data cifs credentials=/home/pi/.smbcredentials,iocharset=utf8 0 0
#save and exit nano
#CREATE FILE TO STORE SMB USER/PASS
nano /home/pi/.smbcredentials
#add RPi samba user/pass (don't add this line)
username=pi
password=raspberry
#save and exit nano
#MOUNT PI
sudo mount -a
#TEST
ls -al /media/Data
#SET ENVIRONMENT VARIABLES
cd
nano .profile
#add lines
export GST_VERSION=1.0
export RPI_ROOT=/home/pi/RPI_ROOT
export RPI_TOOLS=/opt/cross/bin
export TOOLCHAIN_ROOT=/opt/cross/bin
export PLATFORM_OS=Linux
export PLATFORM_ARCH=armv6l
export PKG_CONFIG_PATH=$RPI_ROOT/usr/lib/arm-linux-gnueabihf/pkgconfig:$RPI_ROOT/usr/share/pkgconfig:$RPI_ROOT/usr/lib/pkgconfig
#save and exit nano
#Apply variables
source .profile
#COPY NECESSARY RPI CONTENTS FOR COMPILER
cd
mkdir RPI_ROOT
cd RPI_ROOT
ln -s /media/Data/etc/ etc
ln -s /media/Data/lib/ lib
ln -s /media/Data/opt/ opt
cp -Rv /media/Data/usr/ usr
#FIX HARDCORDED LINKS TO /lib
#TODO Script this: (old fixQualifiedPaths script doesn't work)
cd usr/lib/arm-linux-gnueabihf
rm libudev.so libanl.so libBrokenLocale.so libcidn.so libcrypt.so libdbus-1.so libdl.so libexpat.so libglib-2.0.so liblzma.so libm.so libnsl.so libnss_compat.so libnss_dns.so libnss_files.so libnss_hesiod.so libnss_nisplus.so libnss_nis.so libpcre.so libpng12.so.0 libresolv.so libthread_db.so libusb-0.1.so.4 libusb-1.0.so libutil.so libz.so
ln -s ../../../lib/arm-linux-gnueabihf/libanl.so.1 libanl.so
ln -s ../../../lib/arm-linux-gnueabihf/libBrokenLocale.so.1 libBrokenLocale.so
ln -s ../../../lib/arm-linux-gnueabihf/libcidn.so.1 libcidn.so
ln -s ../../../lib/arm-linux-gnueabihf/libcrypt.so.1 libcrypt.so
ln -s ../../../lib/arm-linux-gnueabihf/libdbus-1.so.3.8.13 libdbus-1.so
ln -s ../../../lib/arm-linux-gnueabihf/libdl.so.2 libdl.so
ln -s ../../../lib/arm-linux-gnueabihf/libexpat.so.1.6.0 libexpat.so
ln -s ../../../lib/arm-linux-gnueabihf/libglib-2.0.so.0 libglib-2.0.so
ln -s ../../../lib/arm-linux-gnueabihf/liblzma.so.5.0.0 liblzma.so
ln -s ../../../lib/arm-linux-gnueabihf/libm.so.6 libm.so
ln -s ../../../lib/arm-linux-gnueabihf/libnsl.so.1 libnsl.so
ln -s ../../../lib/arm-linux-gnueabihf/libnss_compat.so.2 libnss_compat.so
ln -s ../../../lib/arm-linux-gnueabihf/libnss_dns.so.2 libnss_dns.so
ln -s ../../../lib/arm-linux-gnueabihf/libnss_files.so.2 libnss_files.so
ln -s ../../../lib/arm-linux-gnueabihf/libnss_hesiod.so.2 libnss_hesiod.so
ln -s ../../../lib/arm-linux-gnueabihf/libnss_nisplus.so.2 libnss_nisplus.so
ln -s ../../../lib/arm-linux-gnueabihf/libnss_nis.so.2 libnss_nis.so
ln -s ../../../lib/arm-linux-gnueabihf/libpcre.so.3 libpcre.so
ln -s ../../../lib/arm-linux-gnueabihf/libpng12.so.0 libpng12.so.0
ln -s ../../../lib/arm-linux-gnueabihf/libresolv.so.2 libresolv.so
ln -s ../../../lib/arm-linux-gnueabihf/libthread_db.so.1 libthread_db.so
ln -s ../../../lib/arm-linux-gnueabihf/libusb-0.1.so.4 libusb-0.1.so.4
ln -s ../../../lib/arm-linux-gnueabihf/libusb-1.0.so.0.1.0 libusb-1.0.so
ln -s ../../../lib/arm-linux-gnueabihf/libutil.so.1 libutil.so
ln -s ../../../lib/arm-linux-gnueabihf/libz.so.1.2.8 libz.so
ln -s ../../../lib/arm-linux-gnueabihf/libudev.so.1.5.0 libudev.so
cd
#CREATE CROSS COMPILER
mkdir CROSS_BUILD_TOOLS
cd CROSS_BUILD_TOOLS
wget https://gist.githubusercontent.com/jvcleave/ed342fb2d41564bcdab6/raw/495e723cc8e5c64051f3f16697515c5d0eb95f8c/build_cross_gcc.sh
sudo chmod +x build_cross_gcc.sh
sudo ./build_cross_gcc.sh
#TRY AND COMPILE
make -C /media/Data/home/pi/openFrameworks/examples/empty/emptyExample/
#! /bin/bash
set -e
trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
trap 'echo FAILED COMMAND: $previous_command' EXIT
#-------------------------------------------------------------------------------------------
# This script will download packages for, configure, build and install a GCC cross-compiler.
# Customize the variables (INSTALL_PATH, TARGET, etc.) to your liking before running.
# If you get an error and need to resume the script from some point in the middle,
# just delete/comment the preceding lines before running it again.
#
# See: http://preshing.com/20141119/how-to-build-a-gcc-cross-compiler
#-------------------------------------------------------------------------------------------
export SYSROOT=/home/pi/RPI_ROOT
INSTALL_PATH=/opt/cross
TARGET=arm-linux-gnueabihf
LINUX_ARCH=arm
CONFIGURATION_OPTIONS="--disable-werror"
SYSROOT_OPTIONS="--with-sysroot=$SYSROOT --with-build-sysroot=$SYSROOT"
USE_NEWLIB=0
PARALLEL_MAKE=-j4
BINUTILS_VERSION=binutils-2.25.1
GCC_VERSION=gcc-4.9.2
LINUX_KERNEL_VERSION=linux-4.1.7
GLIBC_VERSION=glibc-2.20
MPFR_VERSION=mpfr-3.1.2
GMP_VERSION=gmp-6.0.0a
MPC_VERSION=mpc-1.0.2
ISL_VERSION=isl-0.12.2
CLOOG_VERSION=cloog-0.18.1
export PATH=$INSTALL_PATH/bin:$PATH
# Download packages
export http_proxy=$HTTP_PROXY https_proxy=$HTTP_PROXY ftp_proxy=$HTTP_PROXY
wget -nc https://ftp.gnu.org/gnu/binutils/$BINUTILS_VERSION.tar.gz
wget -nc https://ftp.gnu.org/gnu/gcc/$GCC_VERSION/$GCC_VERSION.tar.gz
wget -nc https://www.kernel.org/pub/linux/kernel/v4.x/$LINUX_KERNEL_VERSION.tar.xz
wget -nc https://ftp.gnu.org/gnu/glibc/$GLIBC_VERSION.tar.xz
wget -nc https://ftp.gnu.org/gnu/mpfr/$MPFR_VERSION.tar.xz
wget -nc https://ftp.gnu.org/gnu/gmp/$GMP_VERSION.tar.xz
wget -nc https://ftp.gnu.org/gnu/mpc/$MPC_VERSION.tar.gz
wget -nc ftp://gcc.gnu.org/pub/gcc/infrastructure/$ISL_VERSION.tar.bz2
wget -nc ftp://gcc.gnu.org/pub/gcc/infrastructure/$CLOOG_VERSION.tar.gz
# Extract everything
for f in *.tar*; do tar xfkv $f; done
# Make symbolic links
cd $GCC_VERSION
ln -sf `ls -1d ../mpfr-*/` mpfr
ln -sf `ls -1d ../gmp-*/` gmp
ln -sf `ls -1d ../mpc-*/` mpc
ln -sf `ls -1d ../isl-*/` isl
ln -sf `ls -1d ../cloog-*/` cloog
cd ..
# Step 1. Binutils
mkdir -p build-binutils
cd build-binutils
../$BINUTILS_VERSION/configure --prefix=$INSTALL_PATH --target=$TARGET $CONFIGURATION_OPTIONS $SYSROOT_OPTIONS
make $PARALLEL_MAKE
make install
cd ..
# Step 2. Linux Kernel Headers
if [ $USE_NEWLIB -eq 0 ]; then
cd $LINUX_KERNEL_VERSION
make ARCH=$LINUX_ARCH INSTALL_HDR_PATH=$INSTALL_PATH/$TARGET headers_install
cd ..
fi
# Step 3. C/C++ Compilers
mkdir -p build-gcc
cd build-gcc
if [ $USE_NEWLIB -ne 0 ]; then
NEWLIB_OPTION=--with-newlib
fi
../$GCC_VERSION/configure --prefix=$INSTALL_PATH --target=$TARGET --enable-languages=c,c++ --with-float=hard $CONFIGURATION_OPTIONS $SYSROOT_OPTIONS
make $PARALLEL_MAKE all-gcc
make install-gcc
cd ..
if [ $USE_NEWLIB -ne 0 ]; then
# Steps 4-6: Newlib
mkdir -p build-newlib
cd build-newlib
../newlib-master/configure --prefix=$INSTALL_PATH --target=$TARGET $CONFIGURATION_OPTIONS
make $PARALLEL_MAKE
make install
cd ..
else
# Step 4. Standard C Library Headers and Startup Files
mkdir -p build-glibc
cd build-glibc
../$GLIBC_VERSION/configure --prefix=$INSTALL_PATH/$TARGET --build=$MACHTYPE --host=$TARGET --target=$TARGET --with-headers=$INSTALL_PATH/$TARGET/include $CONFIGURATION_OPTIONS libc_cv_forced_unwind=yes
make install-bootstrap-headers=yes install-headers
make $PARALLEL_MAKE csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o $INSTALL_PATH/$TARGET/lib
$TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $INSTALL_PATH/$TARGET/lib/libc.so
touch $INSTALL_PATH/$TARGET/include/gnu/stubs.h
cd ..
# Step 5. Compiler Support Library
cd build-gcc
make $PARALLEL_MAKE all-target-libgcc
make install-target-libgcc
cd ..
# Step 6. Standard C Library & the rest of Glibc
cd build-glibc
make $PARALLEL_MAKE
make install
cd ..
fi
# Step 7. Standard C++ Library & the rest of GCC
cd build-gcc
make $PARALLEL_MAKE all
make install
cd ..
trap - EXIT
echo 'Success!'
@timonsku
Copy link

I got so far that I could compile but I'm stuck at a nasty linker issue that I can't resolve:

/opt/cross/bin/arm-linux-gnueabihf-g++ -o bin/emptyExample  obj/linuxarmv7l/Release/src/ofApp.o obj/linuxarmv7l/Release/src/main.o  /media/Data/home/pi/openFrameworks/libs/openFrameworksCompiled/lib/linuxarmv7l/libopenFrameworks.a   -Wl,-rpath=./libs:./bin/libs -Wl,--as-needed -Wl,--gc-sections -pthread -Wl,-rpath -Wl,LIBDIR --sysroot=/home/pi/RPI_ROOT -Wl,-rpath=/home/pi/RPI_ROOT/usr/lib/arm-linux-gnueabihf -Wl,-rpath=/home/pi/RPI_ROOT/lib/arm-linux-gnueabihf -L/home/pi/RPI_ROOT/opt/vc/lib -L/home/pi/RPI_ROOT/usr/lib/arm-linux-gnueabihf /media/Data/home/pi/openFrameworks/libs/glfw/lib/linuxarmv7l/libglfw3.a /media/Data/home/pi/openFrameworks/libs/kiss/lib/linuxarmv7l/libkiss.a /media/Data/home/pi/openFrameworks/libs/tess2/lib/linuxarmv7l/libtess2.a  /media/Data/home/pi/openFrameworks/libs/poco/lib/linuxarmv7l/libPocoNetSSL.a /media/Data/home/pi/openFrameworks/libs/poco/lib/linuxarmv7l/libPocoNet.a /media/Data/home/pi/openFrameworks/libs/poco/lib/linuxarmv7l/libPocoCrypto.a /media/Data/home/pi/openFrameworks/libs/poco/lib/linuxarmv7l/libPocoUtil.a /media/Data/home/pi/openFrameworks/libs/poco/lib/linuxarmv7l/libPocoJSON.a /media/Data/home/pi/openFrameworks/libs/poco/lib/linuxarmv7l/libPocoXML.a /media/Data/home/pi/openFrameworks/libs/poco/lib/linuxarmv7l/libPocoFoundation.a  -L/usr/lib/arm-linux-gnueabihf -lz -lgstapp-1.0 -lgstvideo-1.0 -lgstbase-1.0 -lgstreamer-1.0 -ludev -lfontconfig -lfreetype -lsndfile -lopenal -lssl -lcrypto -lpulse-simple -lpulse -lasound -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lmpg123  -lX11 -lXrandr -lXxf86vm -lXi -lXcursor -ldl -lpthread -lfreeimage -lrtaudio -lboost_filesystem -lboost_system -lGLESv2 -lGLESv1_CM -lEGL -lopenmaxil -lbcm_host -lvcos -lvchiq_arm -lpcre -lrt -lX11 -ldl

/opt/cross/lib/gcc/arm-linux-gnueabihf/4.9.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find -ludev

E: I can also recommend to replace all instances of https://ftp.gnu.org/gnu/ with http://ftpmirror.gnu.org/
The later gives you the closest mirror e.g. a LOT faster downloads than with the main mirror in most cases.

@jvcleave
Copy link
Author

I had those issues as well but they were resolved when I did this part

    PLATFORM_LIBRARY_SEARCH_PATHS += $(SYSROOT)/usr/lib/$(GCC_PREFIX)

    PLATFORM_LDFLAGS += --sysroot=$(SYSROOT) 
    PLATFORM_LDFLAGS += -Wl,-rpath=$(SYSROOT)/usr/lib/$(GCC_PREFIX) 
    PLATFORM_LDFLAGS += -Wl,-rpath=$(SYSROOT)/lib/$(GCC_PREFIX) 

You didn't skip
https://gist.github.com/jvcleave/ed342fb2d41564bcdab6#file-cross-compiler-for-rpi-jessie-openframeworks-0-9-L143

did you?

@timonsku
Copy link

I didn't skip it but I manually patched the changes into the script for the rpi2 (maybe should have mentioned I'm trying it for armv7l). I will check if I missed something there, thanks for the info!

@timonsku
Copy link

Doesn't look like I forgot something to add in my make file:
https://gist.github.com/PTS93/ef4016a6bc38ac1d5cc7#file-config-linuxarmv7l-rpi2-mk

@jvcleave
Copy link
Author

cd ~/RPI_ROOT/usr/lib/arm-linux-gnueabihf
rm libudev.so
ln -s ../../../lib/arm-linux-gnueabihf/libudev.so.1.5.0 libudev.so

@Meach
Copy link

Meach commented Aug 19, 2016

Hi,

When running the last script (build_cross_gcc.sh) I get the following error:

configure: error: GNU libc requires kernel header files from
Linux 2.6.32 or later to be installed before configuring.
The kernel header files are found usually in /usr/include/asm and
/usr/include/linux; make sure these directories use files from
Linux 2.6.32 or later.  This check uses <linux/version.h>, so
make sure that file was built correctly when installing the kernel header
files.  To use kernel headers not from /usr/include/linux, use the
configure option --with-headers.
FAILED COMMAND: ../$GLIBC_VERSION/configure --prefix=$INSTALL_PATH/$TARGET --build=$MACHTYPE --host=$TARGET --target=$TARGET --with-headers=$INSTALL_PATH/$TARGET/include $CONFIGURATION_OPTIONS libc_cv_forced_unwind=yes

I am not using a VM, I am using another computer with Ubuntu 14.04 32-bit installed on it.

@yderidde
Copy link

Hi there,

for some reasons when I run sudo ./build_cross_gcc.sh it fails with the error:

The directory that should contain system headers does not exist:
  /home/pi/RPI_ROOT/usr/include
Makefile:2730: recipe for target 'stmp-fixinc' failed
make[1]: *** [stmp-fixinc] Error 1

I definitely made sure that I go thru all steps without mistake (did the process 3 times). Im not even sure what that error means and therefore where to look to fix it :/
If anyone can help me that would be really appreciated :)

I got a Raspberry Pi2 Model B , using debian-live-8.5.0-amd64-standard.iso in VirtualBox and 2016-05-27-raspbian-jessie.img is installed on my Pi.

@HardwareHaquer
Copy link

HardwareHaquer commented Oct 25, 2016

I am having the same issue as @Meach Meach, did you resolve the libc issue? It looks like the cross folder does not exist in /opt/ ...

looking at the config log these two lines seem to be the problem:

arm-linux-gnueabihf-gcc: error: unrecognized command line option '-qversion'
arm-linux-gnueabihf-gcc: fatal error: no input files

Update: the build_cross_gcc.sh file linked via wget doesn't have the NEWLIB=0 line included. Adding that fixed issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment