下载了一个arm的gcc编译器遇到编译错误
arm-none-eabi/lib/libc.a(lib_a-abort.o): In function `abort‘:
abort.c:(.text+0x10): undefined reference to `_exit‘
/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-signalr.o): In function `_kill_r‘:
signalr.c:(.text+0x1c): undefined reference to `_kill‘
看了手册发现需要设置一个编译选项 --specs=nosys.specs,这次的确编译成功了,但是在Linux系统上运行却SegmentFault。
于是又看了手册发现这个编译器用的时newlib的C库。而linux上的时glibc。同时调用约定和库应该也是不一样的。
原来从arm官网上下载的这个时针对裸版的编译器,没有libc,肯定运行不起来。需要下载
arm-2013.05-24-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2这样的编译器
这个编译器的目录下面有个libc的目录
https://stackoverflow.com/questions/13797693/what-is-the-difference-between-arm-linux-gcc-and-arm-none-linux-gnueabi/13798214
Toolchains have a loose name convention like arch[-vendor][-os]-abi
.
arch
is for architecture: arm, mips, x86, i686...vendor
is tool chain supplier: apple,os
is for operating system: linux, none (bare metal)abi
is for application binary interface convention: eabi, gnueabi, gnueabihf-
- the eabi stands for the compilation of code which will run on bare metal arm core.
- the gnueabi stands for the compilation of code for linux
arm-none-linux-gnueabi
and arm-linux-gnueabi
is same thing. arm-linux-gcc
is actually binary for gcc which produces objects for ARM architecture to be run on Linux with default configuration (abi) provided by toolchain.
例如 https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads 下载的
gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2 目的是给arm的裸版编译程序使用的,它只是linux上的一种安装包,因此编译出来的程序无法在linux上运行
而如果要可以在linux上运行需要使用gnueabi的编译器。
而编译内核和uboot两种编译器都可以用
When compiling .c into .o, the ABI you choose affects which registers are used for parameters, stack-layout etc. When linking the .o into an executable, the ABI have a default linker script and helper objects. But both the kernel and probably u-boot provides their own linker scripts etc, so the ABI for this step is not so important
http://www.veryarm.com/cross-tools
免费版目前有三大主流工具商提供,第一是GNU(提供源码,自行编译制作),第二是 Codesourcery,第三是Linora。
收费版有ARM原厂提供的armcc、IAR提供的编译器等等,因为这些价格都比较昂贵,不适合学习用户使用,所以不做讲述。
- arm-none-linux-gnueabi-gcc:是 Codesourcery 公司(目前已经被Mentor收购)基于GCC推出的的ARM交叉编译工具。可用于交叉编译ARM(32位)系统中所有环节的代码,包括裸机程序、u-boot、Linux kernel、filesystem和App应用程序。
- arm-linux-gnueabihf-gcc:是由 Linaro 公司基于GCC推出的的ARM交叉编译工具。可用于交叉编译ARM(32位)系统中所有环节的代码,包括裸机程序、u-boot、Linux kernel、filesystem和App应用程序。
- aarch64-linux-gnu-gcc:是由 Linaro 公司基于GCC推出的的ARM交叉编译工具。可用于交叉编译ARMv8 64位目标中的裸机程序、u-boot、Linux kernel、filesystem和App应用程序。
- arm-none-elf-gcc:是 Codesourcery 公司(目前已经被Mentor收购)基于GCC推出的的ARM交叉编译工具。可用于交叉编译ARM MCU(32位)芯片,如ARM7、ARM9、Cortex-M/R芯片程序。
- arm-none-eabi-gcc:是 GNU 推出的的ARM交叉编译工具。可用于交叉编译ARM MCU(32位)芯片,如ARM7、ARM9、Cortex-M/R芯片程序。
The bare-metal ABI (eabi) will assume a different C library (newlib for example, or even no C library) to the Linux ABI (gnueabi, which assumes glibc). Therefore, the compiler may make different function calls depending on what it believes is available above and beyond the Standard C library
例如在https://www.linaro.org/downloads/ 网站上有linux和裸版两种编译器的下载
The following tables provide direct access to the most common Linux and bare-metal ABI variants of the Linaro binary cross-toolchain quarterly releases. Both x86_64 Linux and Mingw32 (MS Windows compatible) host binaries are provided:
Latest Linux Targeted Binary Toolchain Releases
arm-linux-gnueabihf | 32-bit ARMv7 Cortex-A, hard-float, little-endian | Release-Notes | Binaries | Source |
armv8l-linux-gnueabihf | 32-bit ARMv8 Cortex-A, hard-float, little-endian | Release-Notes | Binaries | Source |
aarch64-linux-gnu | 64-bit ARMv8 Cortex-A, little-endian | Release-Notes | Binaries | Source |
Latest Bare-Metal Targeted Binary Toolchain Releases
arm-eabi | 32-bit ARMv7 Cortex-A, soft-float, little-endian | Release-Notes | Binaries | Source |
aarch64-elf | 64-bit ARMv8 Cortex-A, little-endian | Release-Notes | Binaries | Source |