Code Monkey home page Code Monkey logo

cross-pi's Introduction

cross-pi

Ubuntu cross compilation to Raspberry PI

cross-pi is a Raspberry PI cross-compiler environment for Kubuntu or Ubuntu, enabling development of Raspberry PI executables from an Ubuntu machine. It is a work in progress and must be considered incomplete in some areas, however the samples work. If you have bug reports or suggested improvements please submit an issue, and it will be considered (no promises though). It is advised to follow these procedures under a disposable virtual machine only, as that ensures an extra layer of safety if something fails. See also the LICENSE.

By following this description and running the scripts, the cross compiler will be built with supporting libraries. On completion, a directory structure will be created:

$HOME/cross-pi                ... Clone of https://github.com/arnholm/cross-pi
$HOME/cross-pi-build          ... Build area
                /buildroot    ... Raspberry PI cross compiler (buildroot.org)
                /libraries    ... Cross compiled optional libraries
                /samples      ... Sample applications to build with cross compiler

The cross compiler is generated using the tools from https://buildroot.org/, see also their User Manual.


Step 1: System preparations

Prepare the operating systems of Ubuntu and Raspberry PI.

Install Kubuntu or Ubuntu - 18.04 or newer

  • Install under Virtual Box
  • Give it a virtual disk of 40GB or more
  • Install git: sudo apt install git
  • From $HOME, clone the repo: git clone https://github.com/arnholm/cross-pi
  • Optional: Install Notepadqq text editor from the script in the utilities folder
  • Optional: configure network disks (/etc/fstab).

cross-pi-bootstrap.sh - Installs essential Ubuntu system packages required for the other scripts to work.


Install Raspbian on the PI - Buster or newer

  • These steps simplify deployment of cross compiled applications to the host PI
  • Enable SSH, use raspi-config to do it.
  • Define static-ip-address. Use "dhcpcd method", editing /etc/dhcpcd.conf
  • Optional: configure network disks (/etc/fstab).

Step 2: cross-pi compiler toolchain

This builds the Raspberry PI cross-compiler toolchain from https://buildroot.org/ under Ubuntu.

cross-pi-buildroot.sh - Builds and installs the cross compiler toolchain. This process requires some user interaction (optionally, perform the steps in the script manually). When the buildroot configuration tool starts, make the following additions (for wxWidgets)

  • Toolchain => C library => (x) glibc
  • Target packages => Graphics libraries and applications => [x] x.org X Window System
  • Target packages => Libraries => Graphics => [x] libgtk2
  • Target packages => Libraries => [x] Cairo

Use File => Save before exiting. You will be asked whether to build the toolchain immediately or do it manually later (be prepared for 2+ hour build). To manually build the toolchain, issue the commands below.

cd ~/cross-pi-build/buildroot
make

After successful build, the cross compiler toolchain is found in this folder:

~/cross-pi-build/buildroot/output/host/usr/bin

When compiling/linking with this toolchain the g++ compiler should be called with the --sysroot=DIR option, where DIR is as below.

~/cross-pi-build/buildroot/output/host/arm-buildroot-linux-gnueabihf/sysroot/
Tool cross-pi name
C compiler arm-linux-gcc
C++ compiler arm-linux-g++
linker for dynamic libs arm-linux-g++
linker for static libs arm-linux-ar

If all you wanted was a cross-compiler, your journey could end here. For libraries and other tools, keep reading.


Step 3: cross-pi libraries

See the libraries subfolder for the scripts mentioned here.

You must complete the cross-pi-buildroot.sh step before running either of them, since the libraries are built using the cross-compiler. Even if you don't plan to build or use these libraries, they serve as examples on how to use the cross-compiler with various build systems.

3.1 cross-pi-boost.sh - Builds cross-pi version of boost libraries

  • Skip this if you don't use boost
  • Uses the cross-compiler with boost jam-file build system
  • Installs to libraries/boost-[version]

3.2 cross-pi-wxwidgets.sh - Builds cross-pi version of wxWidgets libraries

  • Skip this if you don't use wxWidgets
  • Uses the cross-compiler with configure/make build system
  • Build wxWidgets as static libraries
  • Installs to libraries/wxwidgets-[version]

3.3 cross-pi-msgpack-c.sh - Builds cross-pi version of msgpack-c

  • Skip this if you don't use msgpack-c
  • Uses the cross-compiler with cmake build system
  • Installs to libraries/msgpack-c

Step 4: Code::Blocks IDE

See the codeblocks subfolder for the scripts mentioned here.

cross-pi-codeblocks.sh - Installs Code::Blocks IDE and configures it to use with the cross compiler toolchain. You will be asked whether to install Code::Blocks from Ubuntu repository (fast, but old version) or build from source (slower, but up to date).

Step 5: Compile and run samples

See the samples subfolder for the scripts mentioned here. This step requires steps 1-4 to be completed first. Please do NOT open the samples worspace file directly in the cross-pi/samples area, but instead run cross-pi-samples.sh which will make a copy as described below.

cross-pi-samples.sh - Copies the sample application source code to the build area. To build the sample applications, open the Code::Blocks workspace file and build

~/cross-pi-build/samples/SAMPLES.workspace 

When built successfully, the Raspberry PI executables are copied to the staging area at

~/cross-pi-build/samples/stage

cross-pi-scp.sh - Copies the cross-compiled executable(s) found in the staging area to the host Raspberry PI in the PI users Downloads directory. This requires SSH to be enabled on the PI. This script can also be accessed via the Tools menu in Code::Blocks.

cross-pi's People

Contributors

arnholm avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

stahta01

cross-pi's Issues

cross-pi-msgpack-c.sh runing fail

Cloning into 'msgpack-c'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 24233 (delta 6), reused 8 (delta 2), pack-reused 24209
Receiving objects: 100% (24233/24233), 13.32 MiB | 33.00 KiB/s, done.
Resolving deltas: 100% (16262/16262), done.
CMake Error: The source directory "/tmp/build_msgpack-c/msgpack-c" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
make: *** No rule to make target 'install'. Stop.
Error: /home/liuqimin/cross-pi-build/libraries/msgpack-c not found. Build failed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.