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 possible that compile gcc from source on x86 (which will be using on ARM), and how , i do not know how to configure it.
6 Answers
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:
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....
All you need is a cross compiler. You install the cross compiler in your x86 machine and it will generate machine code for arm. I recommend using the GNU arm embedded toolchain.
After which you'd compile exactly as any other c/c++ code except you'd do arm-none-eabi-gcc
(or g++) instead of just gcc or g++
Beware if you are doing bare metal, as functions like printf() may not work without some extra work.
I think you can get the cross compilation toolchain for arm. such as arm-linux-gcc, arm-linux-g++ and so on. Usually the toolchain is an additional product of the arm device. If you want to use the share library(libxxx.so) in application of arm, you can build these library by using the cross compilation toolchain with the source code of the library. For instance, the building step of library for arm is following:
//step 1: configure the cross compilation toolchain in PC. If the
//command line "arm-linux-gcc -v" can implemented in your PC(linux os) , which means the environment is right.
//step 2: get the open source of the library and decompress
tar -zxvf jpegsrc.v6b.tar.gz
//./configure --host=arm-linux --prefix=/your/install/directory
// make && make install
you can get library for arm. I hope that can help you!
There's two solutions to this problem. First is to cross compile the binary and then copy it over. Like:
sudo apt-get install gcc-arm-linux-gnueabi
vi helloworld.c
arm-linux-gnueabi-gcc -o helloworld helloworld.c
then ftp it over.
The other is to cross compile the whole gcc toolchain and copy it over. I suggest doing the first initially. Especially as the initrd is only 8MB and extending it is messy, trying to get the whole operating system onto the sd card is problematic too. You have to compile the bitstream, which requires the 2000 pound version of vivado it seems.