Raspberry Pi: C++ cross-compiling

Environment
  • Ubuntu 16.04 LTS
  • arm-linux-gnueabihf (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  • Raspberry Pi 3 Model B
Install build tools

Check/install build-essential:

# Check if build-essential is installed
$ dpkg -s build-essntial
# Install build-essential if needed
$ sudo apt-get install build-essential
Install ARM toolchain
# ARM build tools
$ sudo apt-get install g++-arm-linux-gnueabihf
# Check installation
$ arm-linux-gnueabihf-g++ -v
Upgrade libstdc++ to 6.0.21 on Raspberry Pi

See Raspberry Pi: how to solve the “version `GLIBCXX_6.0.21′ not found” problem.

Create helloworld.cpp
#include <iostream>

int main() {
    std::cout << "Hello World!" << std::endl;
    return 0;
}
Compile
$ arm-linux-gnueabihf-g++ -O3 -g3 -Wall -fPIC -c -o helloworld.o helloworld.cpp
$ arm-linux-gnueabihf-g++ -o helloworld helloworld.o
Copy helloworld to Raspberry Pi
$ scp ./helloworld pi@192.168.0.xxx:/home/pi/path
Login into Raspberry Pi and run helloworld
$ ssh pi@192.168.0.xxx
# On Raspberry Pi
$ cd path
$ ./helloworld
Hello World!
g++-arm-linux-gnueabihf pakage detais
$ dpkg -s g++-arm-linux-gnueabihf
Package: g++-arm-linux-gnueabihf
Status: install ok installed
Priority: optional
Section: devel
Installed-Size: 11
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Source: gcc-defaults (1.150ubuntu1)
Version: 4:5.3.1-1ubuntu1
Depends: cpp-arm-linux-gnueabihf (>= 4:5.3.1-1ubuntu1), gcc-arm-linux-gnueabihf (>= 4:5.3.1-1ubuntu1), g++-5-arm-linux-gnueabihf (>= 5.3.1-3~)
Description: GNU C++ compiler for the armhf architecture
 This is the GNU C++ compiler, a fairly portable optimizing compiler for C++.
 .
 This is a dependency package providing the default GNU C++ cross-compiler
 for the armhf architecture.
Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>

Fuchsia OS: download, build and run

20161029

Supported build platforms

At the moment of writing two build platforms seems to be supported – Ubuntu and Mac OSx. This article focuses on Ubuntu.

Getting the source

How to install version control tools and checkout Fuchsia OS repositories is described on the Fuchsia Manifest page:

# Install tools
sudo apt-get install golang git-all build-essential curl
# Install jiri scripts
curl -s https://raw.githubusercontent.com/fuchsia-mirror/jiri/master/scripts/bootstrap_jiri | bash -s fuchsia
# Export path to jiri
cd fuchsia
export PATH=`pwd`/.jiri_root/bin:$PATH
# Import/update Fuchsia code
jiri import fuchsia https://fuchsia.googlesource.com/manifest
jiri update

Building Fuchsia

Build instructions can be found in the Fuchsia Repository:

# Setup build environment, amr64
source scripts/env.sh && envprompt && fset arm64
# Build
fbuild

Built sysroot will be in:

fuchsia/out/sysroot/aarch64-fuchsia

and the boot image in:

fuchsia/out/debug-aarch64/user.bootfs

cc

cd fuchsia
git clone https://fuchsia.googlesource.com/third_party/qemu
cd qemu
./configure --target-list=arm-softmmu,aarch64-softmmu,x86_64-softmmu
make -j32
sudo make install

Run Fuchsia OS in QEMU

cd fuchsia/magenta
# Run aarch64 (optionally, with graphical consol - add -g)
./scripts/run-magenta-arm64 -x ../out/debug-aarch64/user.bootfs -m 2048 [-g]

Magenta on Raspberry PI

See Magenta on Raspberry Pi and Raspberry Pi: compile and run Magenta pages.