you can use arm-linux-gnueabihf-gcc hello.c -o hello command. And before you should install arm-linux-gnueabihf-gcc in your linux system .

here is full sample that work for me

Answer from reza rezaee on Stack Overflow
🌐
GNU
gcc.gnu.org › onlinedocs › gcc › ARM-Options.html
ARM Options (Using the GNU Compiler Collection (GCC))
This option is only supported when compiling for ARMv7 M-profile and off by default. It conflicts with -mword-relocations. ... Assume inline assembler is using unified asm syntax. The default is currently off which implies divided syntax. This option has no impact on Thumb2. However, this may change in future releases of GCC.
Discussions

Which gcc is safe for armv7l?
arm-linux-gnueabi is for Linux development and arm-none-eabi is for bare metal. You should choose a supported version, so currently either 9.4, 10.3 or 11.2. I'd go for 11.2 unless you have a good reason to use an older version. More on reddit.com
🌐 r/embedded
9
2
March 11, 2022
c++ - How to compile a gcc compiler for arm on a X86 PC - Stack Overflow
i am using zedboard, I know that if I want to compile a program for an ARM device I need a special version of gcc that runs under x86 and compiles for ARM (cross compiling) ,i want to know is it po... More on stackoverflow.com
🌐 stackoverflow.com
c++ - GCC 8 Cross Compiler outputs ARMv7 executable instead of ARMv6 - Stack Overflow
I'm trying to compile a C++ application for a Raspberry Pi Zero using GCC 8.2.1. I'm using this for a relatively large C++17 project that is being built using CMake, and I'm trying to cross-compile... More on stackoverflow.com
🌐 stackoverflow.com
Cross-compile on Arch Linux host x86_64 for ARM ⇒ Docker image with Rust?

On the topic of cross-compiling from x86_64 to ARM, it doesn't really require much and Docker may be overkill, depending on your goal.

Have you checked the RasPi community for a distro-agnostic cross-compiler tarball?

While my OpenPandora isn't a RasPi, I was able to cross-compile pure Rust code simply by unpacking such a tarball (no Docker needed), identifying the LLVM equivalent to that GCC's target triple (arm-unknown-linux-gnueabi), and then running this command...

rustup target add arm-unknown-linux-gnueabi

...and adding this to ~/.cargo/config:

[target.arm-unknown-linux-gnueabi]
linker = "/home/ssokolow/opt/pandora-dev/arm-2011.09/bin/pandora-gcc"
More on reddit.com
🌐 r/rust
8
8
June 11, 2017
🌐
Arch Linux
aur.archlinux.org › packages › armv7l-gcc
AUR (en) - armv7l-gcc - Arch Linux
Copyright © 2004-2026 aurweb Development Team · AUR packages are user produced content. Any use of the provided files is at your own risk
🌐
Reddit
reddit.com › r/embedded › which gcc is safe for armv7l?
r/embedded on Reddit: Which gcc is safe for armv7l?
March 11, 2022 -

Hello everyone.

I run gentoo for development and use the crossdev tools to generate an arm cross compiler.

I'm having problems finding a version of gcc that behaves when compiling code for armv7l. (gnueabihf).

11.2.X seems to have pie problem (I don't get what pie is, I mean I do conceptually but I don't understand why it is suddenly enabled by default)

I was using 10.5, but gnueabihf wasn't working so I dropped the hf and it worked, but shouldn't it work with Cyclone V?

And I'm confused about how the arch is specified.

Right now I'm using arm-linux-gnueabi, but I wonder if I should be using arm-none-linux-gnueabihf...

Can you guys suggest a known working version of the cross arm tools.

ARM seems to recommend 7.5 and that is way too old for modern linux.

Top answer
1 of 6
4

It is a hard but doable task.

It depends on what ARM series you are compiling against. On many systems you find a Cortex-A (armv7-a or higher) or ARM11 (armv6) processor running a "mini Linux distribution", this is the case for many POS (Point of Sale) devices. In such a case your target can be one of the following:

  • arm-linux-gnueabi
  • arm-linux-gnueabihf

Where hf stands for hard-float, meaning that the CPU has a FPU (floating-point unit), all Cortex-A support this, but also depends on the underlying OS. It is also very important to know the version of the glibc on the embedded Linux, because if versions are not the same between compiler and OS, unexpected behavior may occur.

If you are compiling against an ARM processor without MMU (Memory Magament Unit) like the Cortex-R or Cortex-M series, and that by consequence do not support Linux (only microkernels like FreeRTOS) your target would be (also known as bare-metal):

  • arm-none-eabi

ARM now distributes the binaries of GCC:

https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads

Previously it was Linaro. Yet they keep GCC 7.x for arm-linu-gnueabi (soft-float) if you need it.

https://releases.linaro.org/components/toolchain/binaries/latest-7/

Linaro also used a build system known as ABE, I have not found much documentation on it, but they used it to configure and build the toolchains distributed by them.

If none of the above works for you, you can still build your own toolchain, for that task I suggest using crosstool-ng: https://crosstool-ng.github.io/

Works best under a Linux OS like Ubuntu (you can still try to use Cygwin to build it on Windows, but it may take more time). Note that you do not need to compile it in the machine you want to run it, meaning that you can compile on Ubuntu the GCC that will run on Windows which will produce programs that run on ARM processor, this is known as Canadian Cross.

2 of 6
2

I recommend getting a cross-compiler binary. On a Linux distribution it is often already packaged.

However, if you insist on building GCC from source (but beware of dependencies), read about Installing GCC and about Configuring GCC. You should build it outside of the source tree, and you want to pass some particular --target= option. I also recommend something like --program-suffix=_my

(I have no idea what --target is relevant for your particular configuration & board; you need to find out)

Notice that a target is not only a CPU, but also an OS....

🌐
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
[ap1:~]# uname -m armv7l · 64 ... for ARM. These include the standard tools needed for compiling native: jensd@deb10:~$ sudo apt install gcc make gcc-arm-linux-gnueabi binutils-arm-linux-gnueabi Reading package lists......
🌐
GitHub
gist.github.com › tautologico › 3db84cf76fb85e9e3da8024251530d67
Build gcc cross-compiler for armv7-a (Cortex-A) · GitHub
Build gcc cross-compiler for armv7-a (Cortex-A). GitHub Gist: instantly share code, notes, and snippets.
Find elsewhere
🌐
Arch Linux Forums
bbs.archlinux.org › viewtopic.php
cross compiling for armv7 / Other Architectures / Arch Linux Forums
I solved my problem to cross compile, but I strangely found some dependencies which are mutually exclusive, but requested. So to get arm-linux-gnueabihf-gcc it's required to install arm-linux-gnueabihf-gcc-stage1 that later must supersede by arm-linux-gnueabihf-gcc-stage2, with a relevant volume ...
🌐
GitHub
github.com › siteshwar › gcc › blob › master › cross-armv7l-gcc.spec
gcc/cross-armv7l-gcc.spec at master · siteshwar/gcc
The gcc package contains the GNU Compiler Collection version 4.8. You'll need this package in order to compile C code. ... This package adds C++ support to the GNU Compiler Collection. It includes support for most of the current C++ specification,
Author   siteshwar
🌐
GNU
gcc.gnu.org › onlinedocs › gcc-7.1.0 › gcc › ARM-Options.html
Using the GNU Compiler Collection (GCC): ARM Options
-march=native causes the compiler to auto-detect the architecture of the build computer. At present, this feature is only supported on GNU/Linux, and not all architectures are recognized. If the auto-detect is unsuccessful the option has no effect. ... This option specifies the name of the target ARM processor for which GCC should tune the performance of the code.
🌐
Arm Community
community.arm.com › support-forums › f › armds-forum › 3614 › gcc-for-armv7-a---where-can-i-get-the-latest-version
GCC for ARMv7-A - Where can I get the latest version?
May 19, 2014 - Have a question about working on Arm technology? Browse our support forums for solutions to your questions, answer questions from fellow community members and get help from Arm experts.
🌐
Acmesystems
acmesystems.it › arm9_toolchain
Install the ARM cross compiler toolchain on your Linux PC
It will generate an executable class='acmetable' file for your Linux board. Copy the executable class='acmetable' file on the board via ssh: ... Let's try to cross compile a Hello World example in C++ and running it on an Acme board. ... #include "iostream" using namespace std; int main(int argc, char *argv[]) { cout << "Hello world !" << endl; return 0; } Compile it typing, if you are using an Arietta, Aria or FOX G20 board: ... As you can see we are using the ARM version of gcc just installed on your PC.
🌐
Raisonance
raisonance.com › arm-compiler.html
ARM GCC Compiler - Raisonance
It is also delivered with a range of hardware products including the RLink debugger/programmer, REva starter kit and Primers for ARM core-based devices. This Raisonance software is compatible with 32 and 64-bit versions of Windows 7, 8, 10 and 11. Raisonance RKit-ARM with the GCC C toolchain ...
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.

🌐
Arm Learning
learn.arm.com › install-guides › gcc › cross
Cross-compiler | Arm Learning Paths
You can install a GCC cross compiler with Arm as a target architecture using Linux package managers. Use the apt command to install the cross-compilers for 32-bit and 64-bit Arm Linux targets.