Fedora 13下建立 omap3530 开发环境 - 交叉编译器


准备工作:

假定工作目录在$HOME/devel目录下,其下的

crosstool-ng 用于解压和编译 crosstool-ng,

cortex-a8 用于生成目标工具链。

最终生成的工具链存放于$HOME/x-tools目录下。

在 Fedora 11/12版本中,使用crosstool-ng建立工具链相对容易,不过fedora13下就麻烦很多了,首先下载工具curl下载文件的时候总是不知道下载结束,建议先将crosstool-ng需要的组件先下载下来,放到目标目录的 target/tarballs目录下,再进行编译。

1、到crosstool-ng的官方网站下载最新版本的生成工具,当前最新版本为1.7.1

http://ymorin.is-a-geek.org/projects/crosstool

解压到指定目录下

$ cd $HOME/devel

$ tar -jvxf crosstool-ng-1.7.1.tar.bz2

$ cd crosstool-ng-1.7.1

$ ./configure –local

$ make

新建一个目录cortex-a8,用于生成目标系统。

$ cd $HOME/devel

$ mkdir cortex-a8

$ cd cortex-a8

$ cp ../crosstool-ng-1.7.1/samples/arm-cortex_a8-linux-gnueabi/crosstool.config .config

$ ../crosstool-ng-1.7.1/ct-ng menuconfig

选择 “C-library / extra target CFLAGS”,输入 -U_FORTIFY_SOURCE。

注意:如果不定义这个宏,工具链编译能够通过,www.bkjia.com通过工具链编译u-boot和linux内核也能通过并且正常运行,但glibc中的printf是有问题的,导致使用printf系列函数的应用程序产生段错误,也就是busybox不正常,连命令行都进不去。

同时去掉Native GDB选项,Native GDB是运行在目标板上的原生GDB,即直接在目标板上调试程序,现在用不上。去掉该选项,免得编译出错。

开始编译

$ ../crosstool-ng-1.7.1/ct-ng build.2

这里build.2指的是两个并行编译任务同时运行,一般根据CPU核的数量来确定几个任务。

编译到 ClooG/ppl 时出现如下错误:

[ALL  ]    /usr/bin/ld: /home/xhs/devel/crosstool-ng/cortex-a8/targets/arm-cortex_a8-linux-gnueabi/build/static/lib/libppl.a(MIP_Problem.o): undefined reference to symbol 'sqrt@@GLIBC_2.0' 

[ALL  ]    /usr/bin/ld: note: 'sqrt@@GLIBC_2.0' is defined in DSO /lib/libm.so.6 so try adding it to the linker command line 

[ALL  ]    /lib/libm.so.6: could not read symbols: Invalid operation 

[ALL  ]    collect2: ld returned 1 exit status 

该问题在Fedora12的时候是没有出错的,看错误信息很明显是由于链接时缺少sqrt符号,已知这个函数是在数学库,因此需要在链接时指定-lm参数,可以通过两种方式解决该问题,

1、一种是修改cloog-ppl项目的Makefile.am 增加AM_LDFLAGS=-lm,并通过autoreconf重新生成项目文件。比较麻烦。

2、更简单的方式是修改crosstool-ng的编译脚本,找到crosstool-ng-1.7.1/scripts/build/companion_libs/cloog.sh 定位到 cloog_LDFLAGS='-lstdc++' 这一行,将其改为cloog_LDFLAGS='-lstdc++ -lm'

重新编译,cloog-ppl编译通过,但在编译 gcc-core 和 gcc-final时也遇到同样的问题,找到 crosstool-ng-1.7.1/scripts/build/cc/gcc.sh,找到 core_LDFLAGS='-lstdc++' 和 final_LDFLAGS='-lstdc++'这两行,在其后增加 -lm参数。

重新编译,通过。生成的工具链如果没有修改路径,应该存放在$HOME/x-tools目录下,将其打包成压缩文件以备份劳动成果

$cd

$ tar -jvcf arm-cortex_a8-gcc.tar.bz2 x-tools/

附上crosstool-ng-1.7.1的补丁:

  1. diff -uNr crosstool-ng-1.7.1/scripts/build/cc/gcc.sh crosstool-ng-1.7.1.modified/scripts/build/cc/gcc.sh   
  2. --- crosstool-ng-1.7.1/scripts/build/cc/gcc.sh  2010-06-28 00:38:14.000000000 +0800   
  3. +++ crosstool-ng-1.7.1.modified/scripts/build/cc/gcc.sh 2010-07-13 00:07:32.299329759 +0800   
  4. @@ -155,7 +155,7 @@  
  5.      # the libstdc++ is not pulled automatically, although it  
  6.      # is needed. Shoe-horn it in our LDFLAGS   
  7.      if [ "${CT_COMPLIBS_SHARED}" != "y" ]; then   
  8. -        core_LDFLAGS='-lstdc++'  
  9. +        core_LDFLAGS='-lstdc++ -lm'  
  10.      fi   
  11.      if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then   
  12.          extra_config+=("--with-gmp=${CT_COMPLIBS_DIR}")   
  13. @@ -330,7 +330,7 @@  
  14.      # the libstdc++ is not pulled automatically, although it  
  15.      # is needed. Shoe-horn it in our LDFLAGS   
  16.      if [ "${CT_COMPLIBS_SHARED}" != "y" ]; then   
  17. -        final_LDFLAGS='-lstdc++'  
  18. +        final_LDFLAGS='-lstdc++ -lm'  
  19.      fi   
  20.      if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then   
  21.          extra_config+=("--with-gmp=${CT_COMPLIBS_DIR}")   
  22. diff -uNr crosstool-ng-1.7.1/scripts/build/companion_libs/cloog.sh crosstool-ng-1.7.1.modified/scripts/build/companion_libs/cloog.sh   
  23. --- crosstool-ng-1.7.1/scripts/build/companion_libs/cloog.sh    2010-06-28 00:38:14.000000000 +0800   
  24. +++ crosstool-ng-1.7.1.modified/scripts/build/companion_libs/cloog.sh   2010-07-12 23:41:20.722454427 +0800   
  25. @@ -56,7 +56,7 @@   
  26.          cloog_opts+=( --enable-shared --disable-static )   
  27.      else  
  28.          cloog_opts+=( --disable-shared --enable-static )   
  29. -        cloog_LDFLAGS='-lstdc++'  
  30. +        cloog_LDFLAGS='-lstdc++ -lm'  
  31.      fi   
  32.     
  33.      CFLAGS="${CT_CFLAGS_FOR_HOST}"         

相关内容