Copy‑Paste Setup: Build an ARM32/ARM64 Cross‑Compile Environment on Ubuntu
This guide walks through installing all required packages, configuring ARM32 and ARM64 cross‑compilation toolchains on Ubuntu 18.04/20.04/22.04, verifying the setup with a sample program, and provides commands for fixing common issues and uninstalling the toolchains.
This tutorial targets Ubuntu 18.04, 20.04 and 22.04 and demonstrates how to create a complete ARM32 and ARM64 cross‑compilation environment that can build ARM programs, kernels and drivers on an x86_64 host.
Update package sources and upgrade the system to avoid later dependency errors: sudo apt update && sudo apt upgrade -y Install the basic compilation dependencies that cover most ARM build scenarios:
sudo apt install -y build-essential libc6-dev \
bison flex libssl-dev \
libncurses5-dev git make cmake automake autoconf libtool pkg-configThe build-essential package provides gcc, g++, make and related tools; bison and flex are needed for kernel‑related parsing; libssl-dev supplies cryptographic headers.
Install the ARM cross‑compilation toolchains . The guide distinguishes between ARM32 (32‑bit) and ARM64 (AArch64) and shows the commands for each. After installation, source the profile to make the new tools available: source /etc/profile Verify the environment by generating a simple test source file and compiling it with both toolchains:
echo '#include <stdio.h>
int main(){
printf("ARM Cross Compile Success!
");
return 0;
}' > test.c # ARM32 cross‑compile
arm-linux-gnueabihf-gcc test.c -o test_arm32
# ARM64 cross‑compile
aarch64-linux-gnu-gcc test.c -o test_arm64
# Check the binaries
file test_arm32 test_arm64The file command should report test_arm32 as an ARM32 binary and test_arm64 as an AArch64 binary, confirming that the toolchains work correctly.
If dependency problems or compilation errors occur, the following repair steps are suggested:
# Fix missing dependencies
sudo apt -f install -y
# Reconfigure package database
sudo dpkg --configure -a
# Reinstall the toolchains
sudo apt reinstall gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu -yTo completely remove the toolchains, use:
# Remove ARM32 toolchain
sudo apt remove -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
# Remove ARM64 toolchain
sudo apt remove -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnuWith these commands, the tutorial provides a zero‑configuration, copy‑and‑paste solution for setting up, validating, troubleshooting, and optionally uninstalling an ARM cross‑compilation environment on mainstream Ubuntu releases.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Deepin Linux
Research areas: Windows & Linux platforms, C/C++ backend development, embedded systems and Linux kernel, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
