Install gcc-arm-linux-gnueabi and binutils-arm-linux-gnueabi packages, and then just use arm-linux-gnueabi-gcc instead of gcc for compilation.

You need to be careful on what flavour of linux and binutils you have on your target system. The newest stuff is hardfloat, in this case you would do:

sudo apt-get install gcc-arm-linux-gnueabihf

This brings in the complete cross-compile environment, including binutils.

For using this GCC in the build process write:

CC=arm-linux-gnueabihf-gcc make
Answer from Maratyszcza on askubuntu.com
Top answer
1 of 4
74

Install gcc-arm-linux-gnueabi and binutils-arm-linux-gnueabi packages, and then just use arm-linux-gnueabi-gcc instead of gcc for compilation.

You need to be careful on what flavour of linux and binutils you have on your target system. The newest stuff is hardfloat, in this case you would do:

sudo apt-get install gcc-arm-linux-gnueabihf

This brings in the complete cross-compile environment, including binutils.

For using this GCC in the build process write:

CC=arm-linux-gnueabihf-gcc make
2 of 4
23

64-bit ARM

For 64-bit ARM, the toolchain prefix is aarch64 and usage is:

sudo apt install gcc-aarch64-linux-gnu
aarch64-linux-gnu-gcc -o main.out main.c

You can try it out on this C hello world with QEMU:

main.c

#include <stdio.h>

int main(void) {
    puts("hello");
}

and then:

sudo apt install qemu-user
qemu-aarch64 main.out

will output:

hello

Then a few fun things you can do to quickly see that ARM is actually running under the hood:

  • GDB step debug it: https://stackoverflow.com/questions/20590155/how-to-single-step-arm-assembly-in-gdb-on-qemu/51310791#51310791
  • log the executed ARM instructions with: qemu-aarch64 -d in_asm,out_asm main.out https://stackoverflow.com/questions/13005303/how-does-native-android-code-written-for-arm-run-on-x86/44505097#44505097

Tested in Ubuntu 19.10.

For reliability in serious applications, the disk image provider must also provide a compatible cross compiler

Although you can install a cross compiler with apt conveniently, I must warn you that this is not necessarily reliable unless explicitly supported by the image provider.

If you pick the cross compiler wrongly, the following may happen:

  • the dynamic linker is at the wrong path: https://stackoverflow.com/questions/31929092/trying-to-run-a-cross-compiled-executable-on-target-device-fails-with-no-such-f/49993116#49993116
  • binary incompatibility with the glibc and any other libraries you link against: https://stackoverflow.com/questions/11107263/how-compatible-are-different-versions-of-glibc

Raspberry PI cross compilation

For RPI in particular, the provided cross compilers are available at: https://github.com/raspberrypi/tools and can be used as explained at: https://raspberrypi.stackexchange.com/questions/64273/installing-raspberry-pi-cross-compiler/83215#83215

git clone https://github.com/raspberrypi/tools
export PATH="$(pwd)/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:${PATH}"
printf '#include <stdio.h>\nint main() { puts("hello world"); }\n' > hello_world.c
printf '#include <iostream>\nint main() { std::cout << "hello world" << std::endl; }\n' > hello_world.cpp
arm-linux-gnueabihf-gcc -std=c99 -o hello_world_c hello_world.c
arm-linux-gnueabihf-g++ -std=c++11 -o hello_world_cpp hello_world.cpp

Ubuntu cross compilation

If you want to cross compile for Ubuntu arm64, I have never been able to find a clear reference on which cross compilers support which distro version: What are the officially supported cross compilers for Ubuntu server alternative architectures like ARM?

Buildroot

My favorite alternative is to build your own image with Buildroot: https://stackoverflow.com/questions/47557262/how-to-download-the-torvalds-linux-kernel-master-recompile-it-and-boot-it-wi/49349237#49349237

This builds everything from source, including the toolchain and the image, and ensures that everything is compatible.

🌐
Jensd's I/O buffer
jensd.be › 1126 › linux › cross-compiling-for-arm-or-aarch64-on-debian-or-ubuntu
Cross compiling for arm or aarch64 on Debian or Ubuntu | Jensd's I/O buffer
January 26, 2021 - What is the solution to compile amd64, x86, arm, and aarch64 from on Ubuntu installation? ... Thank for the hint to install gcc-multilib. Installing it helped to compile https://github.com/debmint/osk-disasm ... How can I cross compile xen and xen tools for arm64 in ubuntu 20.04?
🌐
Jensd's I/O buffer
jensd.be › 800 › linux › cross-compiling-for-arm-with-ubuntu-16-04-lts
Cross compiling for ARM with Ubuntu 16.04 LTS | Jensd's I/O buffer
The goal of cross compiling is to compile for one architecture on machine running another one. In this post, I’ll try to explain the steps required to be able to compile software that is executable on ARM-based hardware using a “normal” x64-based PC or virtual machine.
🌐
Arm Learning
learn.arm.com › install-guides › gcc › cross
Cross-compiler | Arm Learning Paths
Use the apt command to install the cross-compilers for 32-bit and 64-bit Arm Linux targets. sudo apt update sudo apt install gcc-arm-linux-gnueabihf -y sudo apt install gcc-aarch64-linux-gnu -y · The GCC version installed is tied to your Ubuntu release. For example, Ubuntu 24.04 LTS provides GCC 13 and Ubuntu 25.10 provides GCC 15.
🌐
Ubuntu Wiki
wiki.ubuntu.com › KernelTeam › ARMKernelCrossCompile
KernelTeam/ARMKernelCrossCompile - Ubuntu Wiki
sudo apt-get install gcc-arm-linux-gnueabi export $(dpkg-architecture -aarmel); export CROSS_COMPILE=arm-linux-gnueabi-
🌐
Acmesystems
acmesystems.it › arm9_toolchain
Install the ARM cross compiler toolchain on your Linux PC
Install the GCC, G++ cross compilers and support programs by typing: sudo apt update sudo apt install libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi libncurses5-dev build-essential bison flex libssl-dev bc
🌐
Stack Overflow
stackoverflow.com › questions › 70824666 › how-to-cross-compile-for-arm-on-ubuntu-conditionally
c - How to cross compile for ARM on Ubuntu conditionally? - Stack Overflow
This makefile is wrong. You've got a object as a target / rule, and you're compiling a binary instead of the object. It works in this case, but it's just wrong generally. ... Set the CROSS_COMPILE variable itself to the compiler prefix.
Find elsewhere
🌐
GitHub
gist.github.com › rikka0w0 › 5c21900f6a6af74d745cd76fe33c7b7c
Setup a ubuntu cross compiling environment for arm · GitHub
Comment out all in: /etc/apt/apt.conf.d/docker-clean and then pt update https://askubuntu.com/questions/735189/enabling-auto-completion-for-apt-get-install-in-docker-ubuntu-14-04/1026978#1026978 https://askubuntu.com/questions/86375/apt-get-autocomplete-package-name-is-broken \ apt install -y sudo nano wget curl git python \ gcc-arm-linux-gnueabi gcc-arm-linux-gnueabihf\ make gcc binutils patch build-essential libssl-dev bc\ flex bison gawk libncurses5-dev gettext autoconf texinfo
🌐
96Boards
96boards.org › documentation › guides › crosscompile › commandline.html
Cross Compile files on x86 Linux host for 96Boards ARM systems - 96Boards
This three part set of instructions will walk you through basic commandline cross compilation on a Linux x86 system for ARM 96Boards devices. Linux host system is used as the cross compiling station · Examples were tested on fully updated Ubuntu 15.04 and 16.04 releases
🌐
Ubuntu
packages.ubuntu.com › search
Ubuntu – Package Search Results -- gcc-arm
October 1, 2020 - noble (24.04LTS) (devel): GCC cross compiler for ARM Cortex-R/M processors [universe] 15:13.2.rel1-2: amd64 arm64 armhf ppc64el riscv64 s390x
🌐
Ubuntu Wiki
wiki.ubuntu.com › MultiarchCross
MultiarchCross - Ubuntu Wiki
To specify these cross-architecture dependencies and build-dependencies :<arch> qualifiers (such as libc6:armhf, libgcc1:powerpc) are use.
🌐
YouTube
youtube.com › watch
Install pre-compiled ARM cross-compiler onto Ubuntu Linux. - YouTube
Tutorial for setting up pre-compiled ARM cross-compiler on Ubuntu Linux.One thing I didn't mention in the video. You can install (using apt) C++ and 64-bit c...
Published   May 23, 2020
🌐
Jasonblog
jasonblog.github.io › note › arm_emulation › using_ubuntu_arm_cross-compiler_for_bare_metal_programming.html
Using Ubuntu ARM cross-compiler for bare metal programming | Jason note
This compiler is a welcome addition (thanks to the maintainer Marcin Juszkiewicz and to the Linaro team) to the default repositories, and it is in line both with the Ubuntu roadmap to appear also on ARM-based devices and with the ARM roadmap to appear also on server solutions. The main purpose of the package is to allow cross-compiling of Linux programs for Ubuntu ARM distributions, but it can be used also for bare metal programming.
🌐
OpenCV
docs.opencv.org › 4.x › d0 › d76 › tutorial_arm_crosscompile_with_cmake.html
OpenCV: Cross compilation for ARM based Linux systems
cmake [<some optional parameters>] -DSOFTFP=ON -DCMAKE_TOOLCHAIN_FILE=<path to the OpenCV source directory>/platforms/linux/arm-gnueabi.toolchain.cmake <path to the OpenCV source directory> For example: ... Optionally you can strip symbols info from the created library via install/strip make target. This option produces smaller binary ( twice smaller) but makes further debugging harder. Depending on target platform architecture different instruction sets can be used. By default compiler generates code for armv5l without VFPv3 and NEON extensions.
Top answer
1 of 1
2

If you notice, you get a message "nothing needs to be done for 'static'" (and friends).

You need to perform a make clean or make distclean to remove the previous i686/x86_64 build.

You should also ensure you are using the latest GNUmakefile-cross and the latest setenv-embedded.sh. If you are using Crypto++ 5.6.3 or above, then its already in Git and you only need to git pull. If you are using Crypto++ 5.6.2 and earlier, then you can download them from ARM Embedded (Command Line).


Here's what it looks like for me on Ubuntu 14.04.

$ . ./setenv-embedded.sh 
CPP: /usr/bin/arm-linux-gnueabi-cpp
CXX: /usr/bin/arm-linux-gnueabi-g++
AR: /usr/bin/arm-linux-gnueabi-ar
LD: /usr/bin/arm-linux-gnueabi-ld
RANLIB: /usr/bin/arm-linux-gnueabi-gcc-ranlib-4.7
ARM_EMBEDDED_TOOLCHAIN: /usr/bin
ARM_EMBEDDED_CXX_HEADERS: /usr/arm-linux-gnueabi/include/c++/4.7.3
ARM_EMBEDDED_FLAGS: -I/usr/arm-linux-gnueabi/include/c++/4.7.3 -I/usr/arm-linux-gnueabi/include/c++/4.7.3/arm-linux-gnueabi
ARM_EMBEDDED_SYSROOT: /usr/arm-linux-gnueabi

$ make -f GNUmakefile-cross 
/usr/bin/arm-linux-gnueabi-g++ -DNDEBUG -g2 -Os -fPIC -pipe
  -I/usr/arm-linux-gnueabi/include/c++/4.7.3
  -I/usr/arm-linux-gnueabi/include/c++/4.7.3/arm-linux-gnueabi
  --sysroot=/usr/arm-linux-gnueabi -c cryptlib.cpp
  ...

And then:

$ /usr/bin/arm-linux-gnueabi-readelf -h ./libcryptopp.a | grep -i 'class\|machine' | head -2
  Class:                             ELF32
  Machine:                           ARM

But I did not get the same output as shown at ARM Embedded (Command Line).

I can't dump things for libcryptopp.so or cryptest.exe because it appears Ubuntu tool chain took a regression. The linker can no longer link an executable.


Ubuntu's cross-compiler is kind of borked. We filed a few bug reports against in when writing the examples on the wiki. Its the reason we provide an example of using ARM's cross-compiler at ARM Embedded (Bare Metal).

Top answer
1 of 2
22

As I told in comments, try

apt-get install gcc-arm-linux-gnueabi 

or

apt-get install gcc-4.7-arm-linux-gnueabi

I also strongly recommend being able to compile an ordinary C program for your Linux system (i.e. learn the basics of gcc, make ... commands and how to use some editor like emacs or gedit ...) and the cross compiler you want also depends upon the system running on your SA1100 hardware board. Don't forget to pass -Wall to any GCC compilation. You probably want to be able to debug your program (pass -g to GCC at compilation, and use the gdb debugger). When your program is running well, compile it with -O2 to ask GCC to optimize its machine code.

Learn to use GNU make -e.g. to write Makefile-s- by reading its documentation and use the arm-linux-gnueabi-gcc as the cross-compiler program. (You might want to use remake to debug your Makefile-s when make does not help enough)

You can get the list of files installed with a package with e.g. dpkg -L gcc-arm-linux-gnueabi

A cross compiled program executable for ARM very probably needs a Linux kernel with some libc (or link it statically) at least on the ARM motherboard, and you need some way to transmit the binary program from the Linux desktop to the ARM hardware.

2 of 2
5

Add the ppa: https://launchpad.net/gcc-arm-embedded The source codes for both are same. Currently supports Ubuntu 10.04/12.04/13.04/13.10/14.04 32 and 64 bit.

Detailed explanations to Launchpad PPA can be found at https://help.launchpad.net/Packaging/. That website explains how a PPA is set up and how to add existing PPA and install software from it.

Here are quick steps to install toolchain from this PPA on Ubuntu before 14.04. Open a terminal and type :

  1. sudo add-apt-repository ppa:terry.guo/gcc-arm-embedded
  2. sudo apt-get update
  3. sudo apt-get install gcc-arm-none-eabi

To remove installed toolchain, just do :

sudo apt-get remove gcc-arm-none-eabi

To update the toolchain, just repeat step 2 and 3.

🌐
LinuxVox
linuxvox.com › blog › building-arm-gnu-cross-compiler
How to Build an ARM GNU Cross Compiler Toolchain on Ubuntu: A Modern Guide for Linux Developers — linuxvox.com
ARCH=arm: Target ARM architecture (use ARCH=arm64 for ARM64). INSTALL_HDR_PATH: Install headers to the toolchain’s include directory. Now build GLIBC using the bootstrap GCC and Linux headers. ... mkdir -p build/glibc cd build/glibc ../../src/glibc-2.38/configure \ --target=$TARGET \ --prefix=$PREFIX/$TARGET \ # Install to toolchain's target directory --host=$TARGET \ # Cross-compiling GLIBC itself --with-headers=$PREFIX/$TARGET/include \ # Linux headers path --enable-multilib \ --disable-werror
🌐
Google
android.googlesource.com › platform › external › armnn › + › refs › heads › upstream-master › BuildGuideCrossCompilation.md
How to Cross-Compile Arm NN on x86_64 for arm64
These are the step by step instructions on Cross-Compiling Arm NN under an x86_64 system to target an Arm64 Ubuntu Linux system. This build flow has been tested with Ubuntu 18.04 and 20.04 and it depends on the same version of Ubuntu or Debian being installed on both the build host and target ...