ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

使用crosstool-ng编译toolchain

2020-01-27 13:54:52  阅读:530  来源: 互联网

标签:gnueabihf toolchain neon ng linux cortexa9 crosstool arm


host为ubuntu16.04

下载相关工具

$ sudo apt-get install automake bison chrpath flex g++ git gperf \
gawk libexpat1-dev libncurses5-dev libsdl1.2-dev libtool \
python2.7-dev texinfo

安装过程

$ git clone https://github.com/crosstool-ng/crosstool-ng.git
$ cd crosstool-ng
$ git checkout crosstool-ng-1.22.0
$ ./bootstrap
$ ./configure --enable-local
$ make
$ make install

--enable-local选项代表安装在当前目录下。

过程中出现configure: error: could not find GNU libtool >= 1.5.26

解决方法

$ sudo apt install libtool-bin

 

列出可用的示例

$ ./ct-ng list-samples

可用加上show前缀来显示具体信息

$ ./ct-ng show-arm-cortexa9_neon-linux-gnueabihf

[L.X] arm-cortexa9_neon-linux-gnueabihf
OS : linux-4.3
Companion libs : gmp-6.0.0a mpfr-3.1.3 mpc-1.0.3 expat-2.1.0 ncurses-6.0
binutils : binutils-2.22
C compilers : gcc | 5.2.0
Languages : C,C++
C library : glibc-2.22 (threads: nptl)
Tools : gdb-7.10

和编译kernel一样,执行下列将sample配置写入.config

$ ./ct-ng arm-cortexa9_neon-linux-gnueabihf

执行下列可进行配置

$ ./ct-ng menuconfig

执行下列命令开始构建

./ct-ng build

 大约一个小时可以编译完成(e3-1230v2),编译完成后会在家目录生产x-tools目录,

~/x-tools/arm-cortexa9_neon-linux-gnueabihf/bin存放二进制编译工具。

PATH=~/x-tools/arm-cortexa9_neon-linux-gnueabihf/bin/:${PATH}加入环境变量

编写测试程序

$ vim test.c
#include <stdio.h>

int main(void)
{
        printf("hello world\n");
        return 0;
}

$ arm-cortexa9_neon-linux-gnueabihf-gcc test.c
$ file a.out 
a.out: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, not stripped

成功编译

 

查看版本信息

$ arm-cortexa9_neon-linux-gnueabihf-gcc --version
arm-cortexa9_neon-linux-gnueabihf-gcc (crosstool-NG crosstool-ng-1.22.0) 5.2.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

查看配置信息

$ arm-cortexa9_neon-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=arm-cortexa9_neon-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/home/rzx/x-tools/arm-cortexa9_neon-linux-gnueabihf/libexec/gcc/arm-cortexa9_neon-linux-gnueabihf/5.2.0/lto-wrapper
Target: arm-cortexa9_neon-linux-gnueabihf
Configured with: /home/rzx/work/crosstool-ng/.build/src/gcc-5.2.0/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=arm-cortexa9_neon-linux-gnueabihf --prefix=/home/rzx/x-tools/arm-cortexa9_neon-linux-gnueabihf --with-sysroot=/home/rzx/x-tools/arm-cortexa9_neon-linux-gnueabihf/arm-cortexa9_neon-linux-gnueabihf/sysroot --enable-languages=c,c++ --with-cpu=cortex-a9 --with-fpu=neon --with-float=hard --with-pkgversion='crosstool-NG crosstool-ng-1.22.0' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --with-gmp=/home/rzx/work/crosstool-ng/.build/arm-cortexa9_neon-linux-gnueabihf/buildtools --with-mpfr=/home/rzx/work/crosstool-ng/.build/arm-cortexa9_neon-linux-gnueabihf/buildtools --with-mpc=/home/rzx/work/crosstool-ng/.build/arm-cortexa9_neon-linux-gnueabihf/buildtools --with-isl=/home/rzx/work/crosstool-ng/.build/arm-cortexa9_neon-linux-gnueabihf/buildtools --with-cloog=/home/rzx/work/crosstool-ng/.build/arm-cortexa9_neon-linux-gnueabihf/buildtools --with-libelf=/home/rzx/work/crosstool-ng/.build/arm-cortexa9_neon-linux-gnueabihf/buildtools --enable-lto --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-plugin --enable-gold --disable-multilib --with-local-prefix=/home/rzx/x-tools/arm-cortexa9_neon-linux-gnueabihf/arm-cortexa9_neon-linux-gnueabihf/sysroot --enable-long-long
Thread model: posix
gcc version 5.2.0 (crosstool-NG crosstool-ng-1.22.0) 

几个重点参数

--with-sysroot=/home/chris/x-tools/arm-cortex_a8-linuxgnueabihf/arm-cortex_a8-linux-gnueabihf/sysroot: This is the default sysroot directory; see the following section for an explanation

--enable-languages=c,c++: Using this, we have both C and C++ languages enabled

--with-cpu=cortex-a8: The code is generated for an ARM Cortex A8 core

--with-float=hard: Generates opcodes for the floating point unit and uses the VFP registers for parameters

--enable-threads=posix: This enables the POSIX threads

这些默认的配置信息可以通过使用时在命令行进行重写,例如

$ arm-cortex_a8-linux-gnueabihf-gcc -mcpu=cortex-a5 helloworld.c \
 -o helloworld

查看相关帮助

$ arm-cortexa9_neon-linux-gnueabihf-gcc --target-help

 

所以说,构建编译链有两种思想:

1.buildroot在开始时就进行详细正确的配置。

2.yocto构建比较通用的形式,针对不同target进行重写。

 

标签:gnueabihf,toolchain,neon,ng,linux,cortexa9,crosstool,arm
来源: https://www.cnblogs.com/-rzx-/p/12233329.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有