Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Instructions for building a Jessie VM to cross-compile openFrameworks 0.9 applications for the Raspberry Pi 1 (arm7)
#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=armv7l
export PLATFORM_VARIANT=rpi2
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
cd usr/lib/arm-linux-gnueabihf
rm 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
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
#PATCH NEEDED UNTIL MERGE OF https://github.com/openframeworks/openFrameworks/pull/4420
cd /media/Data/openFrameworks/libs/openFrameworksCompiled/project/linuxarmv6l
cp config.linuxarmv6l.default.mk config.linuxarmv6l.default.mk.pre-patch
rm config.linuxarmv6l.default.mk
wget https://raw.githubusercontent.com/jvcleave/openFrameworks/f5cc623347a9dc764aabb8d7e0fb81b008d4837a/libs/openFrameworksCompiled/project/linuxarmv6l/config.linuxarmv6l.default.mk
#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"
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.22
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 http://ftpmirror.gnu.org/binutils/$BINUTILS_VERSION.tar.gz
wget -nc http://ftpmirror.gnu.org/gcc/$GCC_VERSION/$GCC_VERSION.tar.gz
wget -nc http://ftpmirror.gnu.org/linux/kernel/v4.x/$LINUX_KERNEL_VERSION.tar.xz
wget -nc http://ftpmirror.gnu.org/glibc/$GLIBC_VERSION.tar.xz
wget -nc http://ftpmirror.gnu.org/mpfr/$MPFR_VERSION.tar.xz
wget -nc http://ftpmirror.gnu.org/gmp/$GMP_VERSION.tar.xz
wget -nc http://ftpmirror.gnu.org/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!'
###############################################################################
# CONFIGURE CORE PLATFORM MAKEFILE
# This file is where we make platform and architecture specific
# configurations. This file can be specified for a generic architecture or can
# be defined as variants. For instance, normally this file will be located in
# a platform specific subpath such as
#
# $(OF_ROOT)/libs/openFrameworksComplied/linux64
#
# This file will then be a generic platform file like:
#
# configure.linux64.default.make
#
# Or it can specify a specific platform variant like:
#
# configure.linuxarmv6l.raspberrypi.make
#
################################################################################
################################################################################
# include common rules
#
# all linux systems have several rules in common so most of them are included
# from the following file
#
################################################################################
include $(OF_SHARED_MAKEFILES_PATH)/config.linux.common.mk
################################################################################
# PLATFORM DEFINES
# Create a list of DEFINES for this platform. The list will be converted into
# CFLAGS with the "-D" flag later in the makefile. An example of fully
# qualified flag might look something like this: -DTARGET_OPENGLES2
#
# DEFINES are used throughout the openFrameworks code, especially when making
# #ifdef decisions for cross-platform compatibility. For instance, when
# choosing a video playback framework, the openFrameworks base classes look at
# the DEFINES to determine what source files to include or what default player
# to use.
#
# Note: Leave a leading space when adding list items with the += operator
################################################################################
# defines used inside openFrameworks libs.
PLATFORM_DEFINES += TARGET_RASPBERRY_PI
# TODO many of these are not relevant to openFrameworks (were just pasted from hello_pi examples)
# from raspberry pi examples
PLATFORM_DEFINES += STANDALONE
PLATFORM_DEFINES += PIC
PLATFORM_DEFINES += _REENTRANT
PLATFORM_DEFINES += _LARGEFILE64_SOURCE
PLATFORM_DEFINES += _FILE_OFFSET_BITS=64
PLATFORM_DEFINES += _FORTIFY_SOURCE
PLATFORM_DEFINES += __STDC_CONSTANT_MACROS
PLATFORM_DEFINES += __STDC_LIMIT_MACROS
PLATFORM_DEFINES += TARGET_POSIX
PLATFORM_DEFINES += HAVE_LIBOPENMAX=2
PLATFORM_DEFINES += OMX
PLATFORM_DEFINES += OMX_SKIP64BIT
PLATFORM_DEFINES += USE_EXTERNAL_OMX
PLATFORM_DEFINES += HAVE_LIBBCM_HOST
PLATFORM_DEFINES += USE_EXTERNAL_LIBBCM_HOST
PLATFORM_DEFINES += USE_VCHIQ_ARM
# Fix for firmware update @
# https://github.com/Hexxeh/rpi-firmware/commit/ca3703d2d282ac96a97650e2e496276727e1b65b
ifeq ($(strip $(shell cat $(RPI_ROOT)/opt/vc/include/interface/vmcs_host/vc_dispmanx.h | grep VC_IMAGE_TRANSFORM_T)),)
PLATFORM_DEFINES += USE_DISPMANX_TRANSFORM_T
endif
################################################################################
# PLATFORM REQUIRED ADDONS
# This is a list of addons required for this platform. This list is used to
# EXCLUDE addon source files when compiling projects, while INCLUDING their
# header files. During core library compilation, this is used to include
# required addon header files as needed within the core.
#
# For instance, if you are compiling for Android, you would add ofxAndroid
# here. If you are compiling for Raspberry Pi, you would add ofxRaspberryPi
# here.
#
# Note: Leave a leading space when adding list items with the += operator
################################################################################
#PLATFORM_REQUIRED_ADDONS = ofxRaspberryPi
################################################################################
# PLATFORM CFLAGS
# This is a list of fully qualified CFLAGS required when compiling for this
# platform. These flags will always be added when compiling a project or the
# core library. These flags are presented to the compiler AFTER the
# PLATFORM_OPTIMIZATION_CFLAGS below.
#
# Note: Leave a leading space when adding list items with the += operator
################################################################################
PLATFORM_CFLAGS += -march=armv7-a
PLATFORM_CFLAGS += -mfpu=vfp
PLATFORM_CFLAGS += -mfloat-abi=hard
PLATFORM_CFLAGS += -fPIC
PLATFORM_CFLAGS += -ftree-vectorize
PLATFORM_CFLAGS += -Wno-psabi
PLATFORM_CFLAGS += -pipe
################################################################################
# PLATFORM LIBRARIES
# These are library names/paths that are platform specific and are specified
# using names or paths. The library flag (i.e. -l) is prefixed automatically.
#
# PLATFORM_LIBRARIES are libraries that can be found in the library search
# paths.
# PLATFORM_STATIC_LIBRARIES is a list of required static libraries.
# PLATFORM_SHARED_LIBRARIES is a list of required shared libraries.
# PLATFORM_PKG_CONFIG_LIBRARIES is a list of required libraries that are
# under system control and are easily accesible via the package
# configuration utility (i.e. pkg-config)
#
# See the helpfile for the -l flag here for more information:
# http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
#
# Note: Leave a leading space when adding list items with the += operator
################################################################################
# raspberry pi specific
PLATFORM_LIBRARIES += GLESv2
PLATFORM_LIBRARIES += GLESv1_CM
PLATFORM_LIBRARIES += EGL
PLATFORM_LIBRARIES += openmaxil
PLATFORM_LIBRARIES += bcm_host
PLATFORM_LIBRARIES += vcos
PLATFORM_LIBRARIES += vchiq_arm
PLATFORM_LIBRARIES += pcre
PLATFORM_LIBRARIES += rt
PLATFORM_LIBRARIES += X11
PLATFORM_LIBRARIES += dl
PLATFORM_LDFLAGS += -pthread
################################################################################
# PLATFORM HEADER SEARCH PATHS
# These are header search paths that are platform specific and are specified
# using fully-qualified paths. The include flag (i.e. -I) is prefixed
# automatically. These are usually not required, but may be required by some
# experimental platforms such as the raspberry pi or other other embedded
# architectures.
#
# Note: Leave a leading space when adding list items with the += operator
################################################################################
# Broadcom hardware interface library
PLATFORM_HEADER_SEARCH_PATHS += $(RPI_ROOT)/opt/vc/include
PLATFORM_HEADER_SEARCH_PATHS += $(RPI_ROOT)/opt/vc/include/IL
PLATFORM_HEADER_SEARCH_PATHS += $(RPI_ROOT)/opt/vc/include/interface/vcos/pthreads
PLATFORM_HEADER_SEARCH_PATHS += $(RPI_ROOT)/opt/vc/include/interface/vmcs_host/linux
##########################################################################################
# PLATFORM LIBRARY SEARCH PATH
# These are special libraries assocated with the above header search paths
# Do not use full flag syntax, that will be added automatically later
# These paths are ABSOLUTE.
# Simply use space delimited paths.
# Note: Leave a leading space when adding list items with the += operator
##########################################################################################
PLATFORM_LIBRARY_SEARCH_PATHS += $(RPI_ROOT)/opt/vc/lib
################################################################################
# PLATFORM CORE EXCLUSIONS
# During compilation, these makefiles will generate lists of sources, headers
# and third party libraries to be compiled and linked into a program or core
# library. The PLATFORM_CORE_EXCLUSIONS is a list of fully qualified file
# paths that will be used to exclude matching paths and files during list
# generation.
#
# Each item in the PLATFORM_CORE_EXCLUSIONS list will be treated as a complete
# string unless teh user adds a wildcard (%) operator to match subdirectories.
# GNU make only allows one wildcard for matching. The second wildcard (%) is
# treated literally.
#
# Note: Leave a leading space when adding list items with the += operator
################################################################################
#PLATFORM_PKG_CONFIG_LIBRARIES += gstreamer-egl-$(GST_VERSION)
PLATFORM_CORE_EXCLUSIONS += $(OF_LIBS_PATH)/openFrameworks/app/ofAppGLFWWindow.cpp
ifeq ($(CROSS_COMPILING),1)
ifdef TOOLCHAIN_ROOT
#You have specified TOOLCHAIN_ROOT with an environment variable
else
TOOLCHAIN_ROOT = /opt/cross/bin
endif
ifdef GCC_PREFIX
#You have specified GCC_PREFIX with an environment variable
else
GCC_PREFIX = arm-linux-gnueabihf
endif
PLATFORM_CXX = $(TOOLCHAIN_ROOT)/$(GCC_PREFIX)-g++
PLATFORM_CC = $(TOOLCHAIN_ROOT)/$(GCC_PREFIX)-gcc
PLATFORM_AR = $(TOOLCHAIN_ROOT)/$(GCC_PREFIX)-ar
PLATFORM_LD = $(TOOLCHAIN_ROOT)/$(GCC_PREFIX)-ld
SYSROOT=$(RPI_ROOT)
PLATFORM_CFLAGS += --sysroot=$(SYSROOT)
PLATFORM_HEADER_SEARCH_PATHS += $(SYSROOT)/usr/include/c++/4.9
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)
PKG_CONFIG_LIBDIR=$(SYSROOT)/usr/lib/pkgconfig:$(SYSROOT)/usr/lib/arm-linux-gnueabihf/pkgconfig:$(SYSROOT)/usr/share/pkgconfig
endif
@jvcleave

This comment has been minimized.

Copy link

commented Oct 30, 2015

putting this here as well as it is needed (was missing in my original)

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

This comment has been minimized.

Copy link

commented Oct 30, 2015

instructions point to my build_cross_gcc.sh
use the one here instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.