closstol-ng制作交叉编译器

crosstool-ng制作交叉编译器
本文档基于凌云物网智科实验室文档制作
1,
>>mkdir crosstool
>>cd crosstool
>>tar -xjf crosstool-ng-1.16.0.tar.bz2
>>cd crosstool-ng-1.16.0
>>ls
bootstrap  configure     contrib  ctng.comp  docs     LICENSES    Makefile.in  README   scripts   TODO config 
configure.ac  COPYING  ctng.in    kconfig  licenses.d  patches      samples  steps.mk

 >>./configure --prefix=`pwd`      配置安装到当前路径下,且命令中间不能有空格

[ligang@localhost crosstool-ng-1.16.0]$ ./configure --prefix=`pwd`
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking for readelf... readelf
checking for absolute path to readelf... /usr/bin/readelf
checking for bison... bison
checking for flex... flex
checking for gperf... gperf
checking for makeinfo... no
configure: error: missing required tool: makeinfo

发现缺少makeinfo命令,但是网上查不到makeinfo的命令,只有用texinfo命令

>>sudo yum install makeinfo

>>sudo yum install texinfo

[ligang@localhost crosstool-ng-1.16.0]$ sudo yum install makeinfo
ÒѼÓÔزå¼þ£ºfastestmirror, refresh-packagekit, security
/var/run/yum.pid Òѱ»Ëø¶¨£¬PID Ϊ 67599 µÄÁíÒ»¸ö³ÌÐòÕýÔÚÔËÐС£
ÁíÍâÒ»¸ö³ÌÐòËø¶¨ÁË yum£»µÈ´ýËüÍ˳ö¡­¡­
[ligang@localhost crosstool-ng-1.16.0]$ sudo yum install texinfo
ÒѼÓÔزå¼þ£ºfastestmirror, refresh-packagekit, security
ÉèÖð²×°½ø³Ì
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: centos.ustc.edu.cn
½â¾öÒÀÀµ¹Øϵ
--> Ö´ÐÐÊÂÎñ¼ì²é
---> Package texinfo.x86_64 0:4.13a-8.el6 will be °²×°
--> Íê³ÉÒÀÀµ¹Øϵ¼ÆËã

>>./configure --prefix='pwd'  再次配置

[ligang@localhost crosstool-ng-1.16.0]$ ./configure --prefix=`pwd`
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking for grep that handles long lines and -e... /bin/grep
checking for libintl.h... yes
。。。。
checking whether gettext is declared... yes
checking ncurses/ncurses.h usability... yes
checking ncurses/ncurses.h presence... yes
checking for ncurses/ncurses.h... yes
checking for library containing initscr... -lncursesw
configure: creating ./config.status
config.status: creating Makefile

>>make && makeinstall

[ligang@localhost crosstool-ng-1.16.0]$ make && make install
  SED    'ct-ng'
  SED    'scripts/crosstool-NG.sh'
  SED    'scripts/saveSample.sh'
  SED    'scripts/showTuple.sh'
。。。
INST    'docs/*.txt'
  MKDIR   '/home/ligang/crosstool/crosstool-ng-1.16.0/share/man/man1/'
  INST    'ct-ng.1.gz'
For auto-completion, do not forget to install 'ct-ng.comp' into
your bash completion directory (usually /etc/bash_completion.d)

 >>cp samples/arm-cortex_a8-linux-gnueabi/crosstool.config .config

>>export TERM=vt100

>>./ct-ng menuconfig       进入配置选项

[ligang@localhost crosstool-ng-1.16.0]$ cp samples/arm-cortex_a8-linux-gnueabi/crosstool.config .config
[ligang@localhost crosstool-ng-1.16.0]$ export TERM=vt100
[ligang@localhost crosstool-ng-1.16.0]$ ./ct-ng menuconfig
  MKDIR config.gen
  IN    config.gen/arch.in

 >>./ct-ng build   注意此时普通账号做事会出现问题

ligang@localhost crosstool-ng-1.16.0]$ ./ct-ng build
[INFO ]  Performing some trivial sanity checks
[INFO ]  Build started 20180126.205130
[INFO ]  Building environment variables
[ERROR]  Destination directory '/opt/x-tools/arm920t' is not removable  //到root账户下做事
[00:00] / make: *** [build] 错误 1

 

[root@localhost crosstool-ng-1.16.0]# ./ct-ng build
[INFO ]  Performing some trivial sanity checks
[INFO ]  Build started 20180126.203753
[INFO ]  Building environment variables
[EXTRA]  Preparing working directories
[ERROR]  Static linking impossible on the host system 'x86_64-build_unknown-linux-gnu'
[00:01] / make: *** [build] 错误 1
[root@localhost crosstool-ng-1.16.0]# ll /opt/x-tools/arm920t/
总用量 8
drwxr-xr-x. 4 root root 4096 1月  26 20:37 arm-arm920t-linux-gnueabi
drwxr-xr-x. 2 root root 4096 1月  26 20:37 lib
lrwxrwxrwx. 1 root root    3 1月  26 20:37 lib32 -> lib
lrwxrwxrwx. 1 root root    3 1月  26 20:37 lib64 -> lib
[root@localhost crosstool-ng-1.16.0]# ^C

 

 发现缺少了一个链接错误要下载相应的库

>>yum install glibc*

[root@localhost crosstool-ng-1.16.0]# yum install glibc*
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: centos.ustc.edu.cn
解决依赖关系
--> 执行事务检查

 

 >>./ct-ng build

[root@localhost crosstool-ng-1.16.0]# ./ct-ng build
[INFO ]  Performing some trivial sanity checks
[INFO ]  Build started 20180126.205605
[INFO ]  Building environment variables
[EXTRA]  Preparing working directories
[EXTRA]  Installing user-supplied crosstool-NG configuration
[EXTRA]  =================================================================
[EXTRA]  Dumping internal crosstool-NG configuration
[EXTRA]    Building a toolchain for:
[EXTRA]      build  = x86_64-unknown-linux-gnu
[EXTRA]      host   = x86_64-unknown-linux-gnu
[EXTRA]      target = arm-arm920t-linux-gnueabi
[EXTRA]  Dumping internal crosstool-NG configuration: done in 0.41s (at 00:06)
[INFO ]  =================================================================
[INFO ]  Retrieving needed toolchain components' tarballs
[EXTRA]    Retrieving 'linux-3.5'
[ERROR]   
[ERROR]  >>
[ERROR]  >>  Build failed in step 'Retrieving needed toolchain components' tarballs'
[ERROR]  >>        called in step '(top-level)'
[ERROR]  >>
[ERROR]  >>  Error happened in: do_kernel_get[scripts/build/kernel/linux.sh@592]
[ERROR]  >>        called from: main[scripts/crosstool-NG.sh@528]
[ERROR]  >>
[ERROR]  >>  For more info on this error, look at the file: 'build.log'
[ERROR]  >>  There is a list of known issues, some with workarounds, in:
[ERROR]  >>      'share/doc/crosstool-ng/ct-ng.1.16.0/B - Known issues.txt'
[ERROR]   
[ERROR]  (elapsed: 0:07.22)
[00:08] / make: *** [build] 错误 1

下载相应库到tarballs下,即binutils-2.20.1a.tar.bz2  gcc-4.4.6.tar.bz2  glibc-ports-2.9.tar.bz2  linux-3.5.tar.bz2     ppl-0.10.2.tar.gz
cloog-ppl-0.15.9.tar.gz   glibc-2.9.tar.bz2  gmp-4.3.2.tar.bz2    mpfr-2.4.2.tar.xz

最好用电脑下载,然后传到secure-CRT下

[ligang@localhost tarballs]$ rz
rz waiting to receive.
Starting zmodem transfer.  Press Ctrl+C to cancel.
Transferring linux-3.5.tar.gz...
  100%   99904 KB 4541 KB/s 00:00:22       0 Errors
?[ligang@localhost tarballs]$ ls
binutils-2.20.1a.tar.bz2  gcc-4.4.6.tar.bz2  glibc-ports-2.9.tar.bz2  linux-3.0.tar.bz2     ppl-0.10.2.tar.gz
cloog-ppl-0.15.9.tar.gz   glibc-2.9.tar.bz2  gmp-4.3.2.tar.bz2        linux-3.5.1.tar.bz2  mpfr-2.4.2.tar.xz

 

 但此时我犯了一个极大错误,就是没有找到linux-3.5.tar.bz2,只看到了linux-3.5.x.tar.bz2版本的,就轻易下了一个linux-3.5.1.tar.bz2的,认为两者一致,并且还尝试了3.0的,

浪费了很多时间,没想到linux-3.5.tar.bz2就再下面,但是没有XX.bz2的,然后就下了XX.gz版本的。其实前面配置菜单Operating System-->Target OS-->Linux Kernel versinon选择是是3.5版本的

 

ligang@localhost tarballs]$ ls
binutils-2.20.1a.tar.bz2  gcc-4.4.6.tar.bz2  glibc-ports-2.9.tar.bz2  linux-3.0.tar.bz2    linux-3.5.tar.gz   ppl-0.10.2.tar.gz
cloog-ppl-0.15.9.tar.gz   glibc-2.9.tar.bz2  gmp-4.3.2.tar.bz2        linux-3.5.1.tar.bz2  mpfr-2.4.2.tar.xz
[ligang@localhost crosstool-ng-1.16.0]$ su
密码:
[root@localhost crosstool-ng-1.16.0]# ./ct-ng build
[INFO ]  Performing some trivial sanity checks
[INFO ]  Build started 20180126.221210
[INFO ]  Building environment variables
[EXTRA]  Preparing working directories
[EXTRA]  Installing user-supplied crosstool-NG configuration
[EXTRA]  =================================================================
[EXTRA]  Dumping internal crosstool-NG configuration
[EXTRA]    Building a toolchain for:
[EXTRA]      build  = x86_64-unknown-linux-gnu
[EXTRA]      host   = x86_64-unknown-linux-gnu
[EXTRA]      target = arm-arm920t-linux-gnueabi
[EXTRA]  Dumping internal crosstool-NG configuration: done in 0.06s (at 00:01)
[INFO ]  =================================================================
[INFO ]  Retrieving needed toolchain components' tarballs
[INFO ]  Retrieving needed toolchain components' tarballs: done in 0.22s (at 00:02)
[INFO ]  =================================================================
[INFO ]  Extracting and patching toolchain components
[EXTRA]    Extracting 'linux-3.5'
[EXTRA]    Patching 'linux-3.5'
[EXTRA]    Extracting 'gmp-4.3.2'
[EXTRA]    Patching 'gmp-4.3.2'
。。。
[INFO ]    Stripping all toolchain executables
[EXTRA]    Installing the populate helper
[EXTRA]    Installing a cross-ldd helper
[EXTRA]    Creating toolchain aliases
[EXTRA]    Removing access to the build system tools
[EXTRA]    Removing installed documentation
[INFO ]  Cleaning-up the toolchain's directory: done in 3.45s (at 33:49)
[INFO ]  Build completed at 20180126.224559
[INFO ]  (elapsed: 33:49.21)
[INFO ]  Finishing installation (may take a few seconds)...
[33:49] /

 测试

>>/opt/x-tools/arm920t/bin/arm-arm920t-linux-gnueabi-gcc -v

[root@localhost crosstool-ng-1.16.0]# /opt/x-tools/arm920t/bin/arm-arm920t-linux-gnueabi-gcc -v
Using built-in specs.
Target: arm-arm920t-linux-gnueabi
Configured with: /home/ligang/crosstool/crosstool-ng-1.16.0/.build/src/gcc-4.4.6/configure
--build=x86_64-build_unknown-linux-gnu --host=x86_64-build_unknown-linux-gnu --target=arm-arm920t-linux-gnueabi
--prefix=/opt/x-tools/arm920t --with-sysroot=/opt/x-tools/arm920t/arm-arm920t-linux-gnueabi/sysroot --enable-languages=c,
c++ --with-arch=armv4t --with-cpu=arm9tdmi --with-tune=arm920t --with-float=soft --with-pkgversion='crosstool-NG 1.16.0'
--enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp
--with-gmp=/home/ligang/crosstool/crosstool-ng-1.16.0/
.build/arm-arm920t-linux-gnueabi/buildtools --with-mpfr=/home/ligang/crosstool/crosstool-ng-1.16.0/.build/arm-arm920t-linux-gnueabi/buildtools
--with-ppl=/home/ligang/crosstool/crosstool-ng-1.16.0/.build/arm-arm920t-linux-gnueabi/buildtools
--with-cloog=/home/ligang/crosstool/crosstool-ng-1.16.0/.build/arm-arm920t-linux-gnueabi/buildtools
--with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix
--enable-target-optspace --disable-nls --disable-multilib --with-local-prefix=/opt/x-tools/arm920t/arm-arm920t-linux-gnueabi/sysroot --enable-c99 --enable-long-long Thread model: posix gcc version 4.4.6 (crosstool-NG 1.16.0

 >>/opt/x-tools/arm920t/bin/arm-arm920t-linux-gnueabi-gcc hello.c -o hello  动态编译c代码

>>/opt/x-tools/arm920t/bin/arm-arm920t-linuxgnueabi-gcc hello.c -o hello -static   静态编译c代码,然后编译后文件明显变大

[ligang@localhost ~]$ file hello.c 
hello.c: UTF-8 Unicode text
[ligang@localhost ~]$ /opt/x-tools/arm920t/bin/arm-arm920t-linux-gnueabi-gcc hello.c -o hello
[ligang@localhost ~]$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.5.0, not stripped
[ligang@localhost ~]$ du -sh hello
8.0K    hello

  >>cd /opt/x-tools/arm920t/bin/

 >>vim symlink.sh            创建 arm-linux-* 符号链接文件 shell 脚本

>>/opt/x-tools/arm920t/bin/arm-linux-gcc -v   测试

[ligang@localhost bin]$ su 
密码:
[root@localhost bin]# vim symlink.sh


   ln -s $file $sym_file 
#!/bin/bash 
for file in `ls arm-*-gnueabi-*` ; do
   sym_file=arm-linux-`echo $file | awk -F '-' '{print $NF}'`   
   ln -s $file $sym_file
done
[root@localhost bin]# bash symlink.sh
[root@localhost bin]# su ligang
[ligang@localhost bin]$  /opt/x-tools/arm920t/bin/arm-linux-gcc -v
Using built-in specs.
Target: arm-arm920t-linux-gnueabi
Configured with: /home/ligang/crosstool/crosstool-ng-1.16.0/.build/src/gcc-4.4.6/configure --build=x86_64-build_unknown-linux-gnu --host=x86_64-build_unknown-linux-gnu --target=arm-arm920t-linux-gnueabi --prefix=/opt/x-tools/arm920t --with-sysroot=/opt/x-tools/arm920t/arm-arm920t-linux-gnueabi/sysroot --enable-languages=c,c++ --with-arch=armv4t --with-cpu=arm9tdmi --with-tune=arm920t --with-float=soft --with-pkgversion='crosstool-NG 1.16.0' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --with-gmp=/home/ligang/crosstool/crosstool-ng-1.16.0/.build/arm-arm920t-linux-gnueabi/buildtools --with-mpfr=/home/ligang/crosstool/crosstool-ng-1.16.0/.build/arm-arm920t-linux-gnueabi/buildtools --with-ppl=/home/ligang/crosstool/crosstool-ng-1.16.0/.build/arm-arm920t-linux-gnueabi/buildtools --with-cloog=/home/ligang/crosstool/crosstool-ng-1.16.0/.build/arm-arm920t-linux-gnueabi/buildtools --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-target-optspace --disable-nls --disable-multilib --with-local-prefix=/opt/x-tools/arm920t/arm-arm920t-linux-gnueabi/sysroot --enable-c99 --enable-long-long
Thread model: posix
gcc version 4.4.6 (crosstool-NG 1.16.0

 

 

 

posted @ 2018-03-15 15:01  李刚blog  阅读(594)  评论(0编辑  收藏  举报