Beginning cross-compilation for Raspberry Pi Zero on Ubuntu

Overview

Run a C language program compiled on Ubuntu on a Raspberry Pi Zero. That's all.

environment

Host: Ubuntu 20.04.1 <Virtual Box 6.1 <Windows 10 Target: Raspberry Pi Zero WH

procedure

Installing the compiler for ARM

$ sudo apt install g++-arm-linux-gnueabi

I need gcc this time, but I may use it in the future, so install g ++. It also installs gcc and whatever you need.

There is also an article that installs g ++-arm-linux-gnueabihf as a cross-compiler for Raspberry Pi, but this does not support Zero CPUs (ARMv6 series).

Build

The program to be built this time before

hogehoge.c


#include <stdio.h>

int main()
{
	printf("Hogehoge Cross!!\n");
	return 0;
}

It ’s the first time, so it ’s like this. Build this like this.

$ arm-linux-gnueabi-gcc -march=armv6 hogehoge.c -o hogehoge_armv6

Specify the ARM architecture with -march =. Since Raspberry Pi Zero is ARMv6 series, I specified it as such, but in this program All worked with armv4, armv5t, armv5te, armv5tej, armv6. The one with armv7 was displayed as" Segmentation fault "and didn't work.

Move

I wrote "It worked" above, but I copied the built hogehoge_armv6 file to an appropriate directory on the Raspberry Pi Zero,

$ ./hogehoge_armv6
Hogehoge Cross!!

It worked like this.

Summary

It's a simple program, but it worked surprisingly easily.

Postscript

I wrote the following article

Recommended Posts

Beginning cross-compilation for Raspberry Pi Zero on Ubuntu
Build wxPython on Ubuntu 20.04 on raspberry pi 4
Cross-compiling for Raspberry Pi Zero on Debian-Try using shared libraries
Set swap space on Ubuntu on Raspberry Pi
Cross-compile for Raspberry Pi Zero on Debian-Create your own shared library
pigpio on Raspberry pi
Play with your Ubuntu desktop on your Raspberry Pi 4
Cython on Raspberry Pi
Control brushless motors with GPIOs on Raspberry Pi Zero
Introduced pyenv on Raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
Run AWS IoT Device SDK for Python on Raspberry Pi
Access google spreadsheet using python on raspberry pi (for myself)
Testing uart communication on Raspberry Pi
MQTT on Raspberry Pi and Mac
Install ghoto2 on Raspberry Pi (memo)
Raspberry pi initial setting (for myself)
Try using ArUco on Raspberry Pi
OpenCV installation procedure on Raspberry Pi
Install confluent-kafka for Python on Ubuntu
Power on / off Raspberry pi on Arduino
Detect switch status on Raspberry Pi 3
Install OpenMedia Vault 5 on Raspberry Pi 4
L Chika on Raspberry Pi C #
"Honwaka Notification Lamp" on Raspberry Pi Part 2
Detect "brightness" using python on Raspberry Pi 3!
Notes for installing Sublime Text on Ubuntu
USB boot on Raspberry Pi 4 Model B
"Honwaka Notification Lamp" on Raspberry Pi Part 1
Enable UART + serial communication on Raspberry Pi
Adafruit Python BluefruitLE works on Raspberry Pi.
Accelerate Deep Learning on Raspberry Pi 4 CPU
Try fishing for smelt with Raspberry Pi
Programming normally with Node-RED programming on Raspberry Pi 3
Use the Grove sensor on the Raspberry Pi
Install 64-bit OS (bate) on Raspberry Pi
"Honwaka Notification Lamp" on Raspberry Pi Part 3
Initial settings for using GrovePi + starter kit and camera on Raspberry Pi
Working with sensors on Mathematica on Raspberry Pi
Build OpenCV-Python environment on Raspberry Pi B +
Detect temperature using python on Raspberry Pi 3!
Mount Windows shared folder on Raspberry Pi
Matrix multiplication on Raspberry Pi GPU (Part 2)
How to install NumPy on Raspberry Pi
I installed OpenCV-Python on my Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
Discord bot with python raspberry pi zero with [Notes]
Media programming with Raspberry Pi (preparation for audio)
Why detectMultiScale () is slow on Raspberry Pi B +
Detect slide switches using python on Raspberry Pi 3!
Build a Django environment on Raspberry Pi (MySQL)
Try using a QR code on a Raspberry Pi
Detect magnet switches using python on Raspberry Pi 3!
Enjoy electronic work with GPIO on Raspberry Pi
Power on / off your PC with raspberry pi
Use Grove-Temperature & Humidity Sensor (DHT11) on Raspberry Pi
Make DHT11 available on Raspberry Pi + python (memo)
Sound the buzzer using python on Raspberry Pi 3!
Build a Kubernetes environment for development on Ubuntu