歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Fedora 13下建立 omap3530 開發環境 - 交叉編譯器

Fedora 13下建立 omap3530 開發環境 - 交叉編譯器

日期:2017/2/28 16:20:11   编辑:Linux教程

准備工作:

假定工作目錄在$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.linuxidc.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. CFLAGS="${CT_CFLAGS_FOR_HOST}"
Copyright © Linux教程網 All Rights Reserved