Raspberry Pi: C++ cross-compiling in Eclipse

Based on this GuruCoding page.

Environment
  • Ubuntu 16.04 LTS
  • Eclipse Neon.3 Release 4.6.3
  • arm-linux-gnueabihf (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  • Raspberry Pi 3 Model B
ARM toolchain

See Raspberry Pi: cross-compiling blog.

Upgrade libstdc++ to 6.0.21 on Raspberry Pi

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

Install Eclipse IDE for C/C++ developers

Download, unpack from here.

Eclipse plugins

Eclipse:

  • Help > Install new software > Work with: –All Available Sites–
  • Check “Mobile and Device Development”
  • Next > Accept the terms of the license agreement” > Finish
  • Restart Eclipse
Create project

In Eclipse:

  • File > New > C++ Project
  • C++ Project
    • Project name: helloworld
    • Project type: Hello World C++ Project
    • Toolchains: Cross GCC
    • Next
  • Basic Settings
    • Hello world greeting: Hello world!
    • Next
  • Select Configurations
    • Next
  • Cross GCC Command
    • Cross compiler prefix: arm-linux-gnueabihf-
    • Cross compiler path: /usr/bin
    • Finish
  • Project > Properties > C/C++ Build > Settings
    • Tool Settings > Cross Settings
      • Prefix: arm-linux-gnueabihf-
      • Path: /usr/bin
Enable C++ 11
  • Project > Properties > C/C++ Build > Settings
    • Configuration: Debug/Release
    • Tool Settings > Cross G++ Compiler > Dialect: ISO C+11 (-std=c++0x)
Build
  • Project > Build All

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>