最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【总结】crosstool-ng使用心得和注意事项

crosstool-ng crifan 6596浏览 0评论

【背景】

之前折腾,用crosstool-ng去编译arm-xscale-linux-gnueabi:

【记录】crosstool为xscale编译(ct-ng build)过程

【记录】重试使用最新版本1.18.0的crosstool-ng去配置和编译xscale的交叉编译器

遇到很多问题和情况,然后有些心得,总结如下:

 

crosstool-ng的基本使用方法

安装crosstool-ng

先配置一下:

CLi@PC-CLI-1 ~/develop/crosstool-ng
$ ls
crosstool-ng-1.9.3  crosstool-ng-1.9.3.tar
 
CLi@PC-CLI-1 ~/develop/crosstool-ng
$ cd crosstool-ng-1.9.3/
 
CLi@PC-CLI-1 ~/develop/crosstool-ng/crosstool-ng-1.9.3
$ ls
config  configure  contrib  COPYING  ct-ng.comp  ct-ng.in  docs  kconfig  LICENSES  licenses.d  Makefile.in  patches  README  samples  scripts  steps.mk  TODO
 
CLi@PC-CLI-1 ~/develop/crosstool-ng/crosstool-ng-1.9.3
$ ./configure --prefix=/opt/crosstool-ng
Checking for 'grep'... /usr/bin/grep
Checking whether '/usr/bin/grep' supports -E... yes
Checking for 'sed'... /usr/bin/sed
Checking whether '/usr/bin/sed' supports -i and -e... yes
Checking for 'bash'... /usr/bin/bash
Checking for 'cut'... /usr/bin/cut
Checking for 'install'... /usr/bin/install
Checking for 'make'... /usr/bin/make
Checking for 'gcc'... /usr/bin/gcc
Checking for 'awk'... /usr/bin/awk
Checking for 'bison'... /usr/bin/bison
Checking for 'flex'... /usr/bin/flex
Checking for 'makeinfo'... /usr/bin/makeinfo
Checking for 'automake'... /usr/bin/automake
Checking for 'libtool'... /usr/bin/libtool
Checking for 'stat'... /usr/bin/stat
Checking for 'aria2c'... /usr/bin/aria2c
Checking for 'cvs'... /usr/bin/cvs
Checking for 'patch'... /usr/bin/patch
Checking for 'tar'... /usr/bin/tar
Checking for 'gzip'... /usr/bin/gzip
Checking for 'bzip2'... /usr/bin/bzip2
Checking for 'lzma'... /usr/bin/lzma
Checking for 'readlink'... /usr/bin/readlink
Checking for 'objcopy'... /usr/bin/objcopy
Checking for 'objdump'... /usr/bin/objdump
Checking for 'readelf'... /usr/bin/readelf
Checking for 'patch'... /usr/bin/patch
Checking for 'ncurses/ncurses.h'... yes
Checking for 'libncursesw.so'... no
Checking for 'libncursesw.a'... yes
Computing version string... 1.9.3
Building up Makefile... done
 
crosstool-NG configured as follows:
  PREFIX='/opt/crosstool-ng'
  BINDIR='/opt/crosstool-ng/bin'
  LIBDIR='/opt/crosstool-ng/lib/ct-ng-1.9.3'
  DOCDIR='/opt/crosstool-ng/share/doc/ct-ng-1.9.3'
  MANDIR='/opt/crosstool-ng/share/man'
 
Now run:
  make
  make install
 
CLi@PC-CLI-1 ~/develop/crosstool-ng/crosstool-ng-1.9.3
$

再安装:

CLi@PC-CLI-1 ~/develop/crosstool-ng/crosstool-ng-1.9.3
$ make
  SED    'ct-ng'
  SED    'scripts/crosstool-NG.sh'
  SED    'scripts/saveSample.sh'
  SED    'scripts/showTuple.sh'
  GEN    'paths.mk'
  SED    'docs/ct-ng.1'
  GZIP   'docs/ct-ng.1.gz'
 
CLi@PC-CLI-1 ~/develop/crosstool-ng/crosstool-ng-1.9.3
$ make install
  MKDIR   '/opt/crosstool-ng/bin/'
  INST    'ct-ng'
  RMDIR   '/opt/crosstool-ng/lib/ct-ng-1.9.3/'
  MKDIR   '/opt/crosstool-ng/lib/ct-ng-1.9.3/'
  INSTDIR 'config/'
  INSTDIR 'contrib/'
  INSTDIR 'kconfig/'
  INSTDIR 'patches/'
  INSTDIR 'scripts/'
  INST    'steps.mk'
  INST    'paths.mk'
  INSTDIR 'samples/'
  MKDIR   '/opt/crosstool-ng/share/doc/ct-ng-1.9.3/'
  INST    'docs/*.txt'
  MKDIR   '/opt/crosstool-ng/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)
 
CLi@PC-CLI-1 ~/develop/crosstool-ng/crosstool-ng-1.9.3
$

然后就可以接着去使用crosstool-ng去编译交叉编译器了。

 

使用crosstool-ng

 

使用默认配置

ct-ng SAMPLE_CONFIG_NAME

其中SAMPLE_CONFIG_NAME是crosstool-ng提供的,已有的,默认的模板,示例,配置,供你参考使用的。

具体有哪些sample,可以通过list-samples查到:

CLi@PC-CLI-1 ~/develop/crosstool-ng/crosstool-ng-1.9.3_build
$ ct-ng list-samples
Sample name                           Status
alphaev56-unknown-linux-gnu           [G X]
arm-bare_newlib_cortex_m3_nommu-eabi  [G X]
arm-cortex_a8-linux-gnueabi           [G  ]
arm-davinci-linux-gnueabi             [G  ]
arm-iphone-linux-gnueabi              [G X]
arm-unknown-eabi                      [G  ]
arm-unknown-linux-gnueabi             [G  ]
arm-unknown-linux-uclibcgnueabi       [G X]
armeb-test_nptl-linux-uclibcgnueabi   [G X]
armeb-unknown-eabi                    [G  ]
armeb-unknown-linux-gnueabi           [G X]
armeb-unknown-linux-uclibcgnueabi     [G X]
avr32-unknown-none                    [G X]
bfin-unknown-linux-uclibc             [G  ]
i586-geode-linux-uclibc               [G  ]
mingw32,i686-none-linux-gnu           [G X]
i686-nptl-linux-gnu                   [G  ]
i686-pc-mingw32                       [G X]
ia64-unknown-linux-gnu                [G X]
m68k-unknown-elf                      [G X]
mips-ar2315-linux-gnu                 [G X]
mips-unknown-elf                      [G  ]
mips-unknown-linux-uclibc             [G  ]
mips64el-n32-linux-uclibc             [G X]
mips64el-n64-linux-uclibc             [G X]
mipsel-unknown-linux-gnu              [G  ]
powerpc-405-linux-gnu                 [G  ]
powerpc-860-linux-gnu                 [G  ]
powerpc-e500v2-linux-gnuspe           [G X]
powerpc-unknown-linux-gnu             [G  ]
powerpc-unknown-linux-uclibc          [G  ]
powerpc-unknown_nofpu-linux-gnu       [G  ]
powerpc64-unknown-linux-gnu           [G X]
s390-ibm-linux-gnu                    [G X]
s390x-ibm-linux-gnu                   [G X]
sh4-unknown-linux-gnu                 [G  ]
x86_64-unknown-linux-gnu              [G  ]
x86_64-unknown-linux-uclibc           [G  ]
      L (Local)       : sample was found in current directory
      G (Global)      : sample was installed with crosstool-NG
      X (EXPERIMENTAL): sample may use EXPERIMENTAL features
      B (BROKEN)      : sample is currently broken

 

其中,想要看看那个sample具体是哪些配置,可以用show-samplename查得:

CLi@PC-CLI-1 ~/develop/crosstool-ng/crosstool-ng-1.9.3_build
$ ct-ng show-arm-cortex_a8-linux-gnueabi
arm-cortex_a8-linux-gnueabi  [G  ]
    OS             : linux-2.6.36
    Companion libs : gmp-4.3.2 mpfr-2.4.2 ppl-0.10.2 cloog-ppl-0.15.9 libelf-0.8.13
    binutils       : binutils-2.20
    C compiler     : gcc-4.4.3 (C,C++)
    C library      : glibc-2.9
    Tools          : dmalloc-5.5.2 duma-2_5_15 gdb-6.8 ltrace-0.5.3 strace-4.5.19

 

所以,想要用那个cortex a8的配置,就可以用:

CLi@PC-CLI-1 ~/develop/crosstool-ng/crosstool-ng-1.9.3_build
$ ct-ng arm-cortex_a8-linux-gnueabi
  MKDIR kconfig
  DEP   kconfig/conf.dep
  DEP   kconfig/zconf.tab.dep
  CC    kconfig/zconf.tab.o
  CC    kconfig/conf.o
  LD    kconfig/conf
  LN    config
  MKDIR config.gen
  IN    config.gen/arch.in
  IN    config.gen/kernel.in
  IN    config.gen/cc.in
  IN    config.gen/libc.in
  IN    config.gen/debug.in
  CONF  config/config.in
 
***********************************************************
 
Initially reported by: Yann E. MORIN
URL: http://ymorin.is-a-geek.org/
 
***********************************************************
 
Now configured for "arm-cortex_a8-linux-gnueabi"

 

配置crosstool-ng

ct-ng menuconfig

记得修改成你自己的配置后,退出之前,要去save一下。

 

开始编译

ct-ng build

 

注:

也可以参考下面的"关于记住之前编译到哪个阶段,如何继续从该阶段继续编译"去从某一步直接开始接着编译。

适用于:

之前出错,然后解决了该错误,然后希望从之前出错的那一步骤,接着编译。

 

关于用多线程编译

1.之前别人说的用

ct-ng build.4

表示是用4个线程去编译,

经过实测发现,当前,在已经配置,线程为4,之后,直接

ct-ng build

和上面效果一样的:

也是用4个线程去编译的。

这点,可以从之前多次中间编译出错,比如:

【未解决】crosstool-ng在Installing C library headers & start files期间出错:Makefile:240: *** mixed implicit and normal rules.  Stop.

中的:

Current command: ‘make’ ‘-j4‘ ‘-l’ ‘install_root=/home/CLi/develop/crosstool-ng/x-tools/arm-xscale-linux-gnueabi/arm-xscale-linux-gnueabi/sysroot’ ‘install-bootstrap-headers=yes’ ‘install-headers’

而看出。

 

官网已提供了一些常见错误的解决办法

在编译遇到一些错误时,可以先去参考,crosstool-ng自带的,常见问题集锦:

crosstool-ng\crosstool-ng-1.18.0\docs\B – Known issues.txt

其中会给该问题的解决办法的。

比如这个问题的:

【已解决】编译crosstool-ng在Installing kernel headers时出错:/home/CLi/develop/crosstool-ng/crosstool-ng-1.18.0_build /.build/src/linux-custom/Makefile:1444: *** mixed implicit and normal rules. Stop.

里面就有解决办法的。

 

关于记住之前编译到哪个阶段,如何继续从该阶段继续编译

由于编译crosstool-ng比较耗时间,一般都是2+小时,所以,如果是后续的某一步出错,改了错,再去重新编译,就显得极其耗时间。

而crosstool-ng,最新版本,比如我此处的1.18.0,支持通过打开调试选项中的记住之前哪一步,而支持:

指定从哪一步编译

指定只编译哪一步

指定从开始编译到哪一步

如何打开:

Paths and misc options  —>

[*]Debug crosstool-NG

[*]Save intermediate steps

如何使用:

先去:

ct-ng list-steps

可以显示出目前一共多少步:

CLi@PC-CLI-1 ~/develop/crosstool-ng/crosstool-ng-1.18.0_build
$ ct-ng list-steps
Available build steps, in order:
  - libc_check_config
  - companion_libs_for_build
  - binutils_for_build
  - companion_libs_for_host
  - binutils_for_host
  - cc_core_pass_1
  - kernel_headers
  - libc_start_files
  - cc_core_pass_2
  - libc
  - cc_for_build
  - cc_for_host
  - libelf_for_target
  - binutils_for_target
  - debug
  - test_suite
  - finish
Use "<step>" as action to execute only that step.
Use "+<step>" as action to execute up to that step.
Use "<step>+" as action to execute from that step onward.

然后选择你要的那一步,去继续执行即可,比如:

ct-ng libc_start_files+

 

又比如,我另外的一次的是从binutils_for_host开始继续编译的:

CLi@PC-CLI-1 ~/develop/crosstool-ng/crosstool-ng-1.18.0_build
$ ct-ng binutils_for_host+
[INFO ]  Performing some trivial sanity checks
[INFO ]  Build started 20130801.093212
[INFO ]  Building environment variables
[EXTRA]  Preparing working directories
[EXTRA]  Restoring state at step 'binutils_for_host', as requested.
[INFO ]  =================================================================
[INFO ]  Installing binutils for host
[EXTRA]    Configuring binutils
[EXTRA]    Building binutils
[EXTRA]    Installing binutils
[INFO ]  Installing binutils for host: done in 598.20s (at 10:24)
[EXTRA]  Saving state to restart at step 'cc_core_pass_1'...
[INFO ]  =================================================================
[INFO ]  Installing pass-1 core C compiler
[EXTRA]    Configuring gcc
[EXTRA]    Building gcc
[13:52] /

其中,注意到,这句:

Saving state to restart at step ‘cc_core_pass_1’…

就是去保存当前此步的状态的,以供下次恢复从此步骤继续执行提供状态信息。

 

注意:

当然,使用此功能的前提是:

你的确已经编译到了某一步了。否则使用此功能,会提示你出错,说你之前没有编译到该步的:

[ERROR]  The previous build did not reach the point where it could be restarted at ‘libc_start_files’

详见:

【未解决】crosstool-ng在Installing C library headers & start files期间出错:Makefile:240: *** mixed implicit and normal rules.  Stop.

 

4.

转载请注明:在路上 » 【总结】crosstool-ng使用心得和注意事项

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.177 seconds, using 22.06MB memory