主机升级到Fedora 14,下载了crosstool-ng-1.10.0,编译目标为 arm-cortex_a8。
编译步骤:
1、直接拷贝 crosstool-ng-1.10.0/samples/arm-cortex_a8-linux-gnueabi/crosstool.config 到目标目录中的 .config
2、执行 ct-ng menuconfig 查看和校验编译选项,不做任何改动。
3、执行 ct-ng build,如果想加快编译速度,并且主机具备多核,则可以使用选项build.X来编译,其中X表示使用的线程数,一般最多为主机核心的2倍就足够。
编译并未如期通过,出现如下错误:
[INFO ]
[INFO ] Installing static core C compiler
[EXTRA]Configuring static core C compiler
[EXTRA]Building static core C compiler
[ERROR]make[2]: *** [cc1-dummy] Error 1
[ERROR]make[1]: *** [all-gcc] Error 2
[ERROR]Build failed in step 'Installing static core C compiler'
[ERROR]Error happened in '/home/sam/devel/devkit8000/crosstool-ng/crosstool-ng-1.10.0/scripts/functions' in function 'CT_DoExecLog' (line unknown, sorry)
[ERROR] called from '/home/sam/devel/devkit8000/crosstool-ng/crosstool-ng-1.10.0/scripts/build/cc/gcc.sh' at line # 320 in function 'do_cc_core'
[ERROR] called from '/home/sam/devel/devkit8000/crosstool-ng/crosstool-ng-1.10.0/scripts/build/cc/gcc.sh' at line # 52 in function 'do_cc_core_pass_1'
[ERROR] called from '/home/sam/devel/devkit8000/crosstool-ng/crosstool-ng-1.10.0/scripts/crosstool-NG.sh' at line # 606 in function 'main'
[ERROR]Look at '/home/sam/x-tools/arm-cortex_a8-linux-gnueabi/build.log' for more info on this error.
[ERROR] (elapsed: 10:11.57)
[10:11] / make: *** [build] 错误 2
错误是在第一次编译静态GCC时出错的,按照出错提示查看编译日志build.log,找到如下错误信息:
[ALL ]/usr/bin/ld: cannot find -lstdc++
[ALL ]collect2: ld returned 1 exit status
[ERROR]make[2]: *** [cc1-dummy] Error 1
看来是链接程序找不到 libstdc++ 所致,启动ct-ng menuconfig, 进入菜单 C Compiler,可以看到
[*] Link libstdc++ statically into the gcc binary
选项,GCC在编译时被静态链接了,也就是没有生成libstdc++.so,所以导致libstdc++连接不到,因此去掉该选项,再次编译。
出现如下错误:
[INFO ] Installing C library headers
[EXTRA]Configuring C library
[EXTRA]Installing C library headers
[ERROR]make[3]: *** [manual/install-headers] Error 2
[ERROR]make[2]: *** [install-headers] Error 2
[ERROR]Build failed in step 'Installing C library headers'
[ERROR]Error happened in '/home/sam/devel/devkit8000/crosstool-ng/crosstool-ng-1.9.3/scripts/functions' in function 'CT_DoExecLog' (line unknown, sorry)
[ERROR] called from '/home/sam/devel/devkit8000/crosstool-ng/crosstool-ng-1.9.3/scripts/build/libc/glibc.sh' at line # 175 in function 'do_libc_headers'
[ERROR] called from '/home/sam/devel/devkit8000/crosstool-ng/crosstool-ng-1.9.3/scripts/crosstool-NG.sh' at line # 597 in function 'main'
[ERROR]Look at '/home/sam/x-tools/arm-cortex_a8-linux-gnueabi/build.log' for more info on this error.
[ERROR] (elapsed: 38:55.31)
[38:56] / make[1]: *** [build] 错误 2
make: *** [build.4] 错误 2
可见错误的是在编译GLIBC时发生的,打开build.log,可以看到如下错误信息:
[ALL ]make[4]: Entering directory `/home/sam/devel/devkit8000/crosstool-ng/arm-cortex_a8/.build/src/glibc-2.9/manual'
[ALL ]Makefile:240: *** mixed implicit and normal rules. Stop.
原来是新的Fedora 14使用的make不支持原来的显示规则和隐式规则混和的写法,后来查看make的版本从fedora13到fedora14进行了一次小升级,从3.81升级到了3.82,但就是这个小升级移除了对makefile中的显示规则和隐式规则的混和使用的支持,因此编译通不过。
这还真是一个比较纠结的问题,有较多的软件已经习惯了make对两种规则的混用支持,如果移除规则就算解决了glibc,其它软件编译极可能还会出现类似问题,看来不得不降级make的版本了。
为了编译通过,先将make降到Fedora13所使用的3.81版本。
yum --releasever=13 downgrade make
重新编译,顺利通过。
经验:
如果编译失败,但build.log最后看不到明显的错误信息,则可能是由于并行编译所致,并行编译在log中的记录也会被打乱顺序,致使错误信息看不准确。此时只要不使用并行编译,就会使错误信息在log中准确记录。