简体   繁体   中英

How to compile a gcc compiler for arm on a X86 PC

我正在使用 zedboard,我知道如果我想为 ARM 设备编译程序,我需要一个特殊版本的 gcc,它可以在 x86 下运行并为 ARM 编译(交叉编译),我想知道是否可以从x86 上的源代码(将在 ARM 上使用),以及如何配置,我不知道如何配置它。

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....

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.

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.

You can use these commands on x86:

For ARM 32b:

arm-linux-gnueabi-gcc

For ARM 64b:

aarch64-linux-gnu-gcc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM