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.comInstall 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
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.outhttps://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.
TLDR
you need to call arm-linux-gnueabi-gcc not arm-linux-gcc.
It looks like you've just got the wrong file name. For reference apt-file is a useful tool.
sudo apt-get install apt-file
sudo apt-file update
apt-file search -x 'gcc$' | grep 'gcc-arm-linux-gnueabi'
This searches any file ending gcc in any package with gcc-arm-linux-gnueabi in the name. The result is:
gcc-arm-linux-gnueabi: /usr/bin/arm-linux-gnueabi-gcc
So if you have installed gcc-arm-linux-gnueabi you should have a file /usr/bin/arm-linux-gnueabi-gcc.
As steeldriver suggests, you already have installed the cross-compiler; the problem is that you’re using the wrong command to invoke it, you need to use the arm-linux-gnueabi- prefix in general. So run
arm-linux-gnueabi-gcc
or
arm-linux-gnueabi-g++
and it should work fine.
To figure this out yourself, you can use dpkg -L to list the contents of the packages you’ve installed:
dpkg -L gcc-arm-linux-gnueabi
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.
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 :
sudo add-apt-repository ppa:terry.guo/gcc-arm-embeddedsudo apt-get updatesudo 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.
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.
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....