閱讀997 返回首頁    go 阿裏雲 go 技術社區[雲棲]


arm-linux-gcc下載與安裝

在RHEL 5平台上安裝配置arm-linux-gcc  2011-02-23 19:35:40|  分類: 嵌入式開發環境 |  標簽: |字號大中小 訂閱 .

在linux平台上安裝好的基礎上,開始配置arm-linux-gcc,使其正常工作

一,安裝前準備

1,下載並安裝arm-linux-gcc

arm-linux-gcc-4.2.1的版本在https://ftp.snapgear.org/pub/snapgear/tools/arm-linux/這裏可以下載,最新版arm-linux-tools-20080623.tar.gz這個可能是4.2.4的版本,因為下麵有編譯4.2.4的方法還有相應的代碼包,build-arm-linux-4.2.14,此版本由於過大,我沒有下載。

下麵的這個是ARM官方給的下載鏈接https://www.codesourcery.com/gnu_toolchains/arm/download.html,然後將HOST選擇為IA32 GNU/Linux,點擊下載就可以了。不過前綴為arm-2010.09-51-arm-none-eabi-i686-pc-linux-gnu而不是arm-linux-。。。

       在友善之臂官方網站https://www.arm9.net/download.asp下載arm-linux-gcc4.4.3。

2,刪除之前安裝有舊版本,執行

 [root@localhost ~]# rm -rf /opt/arm

3,對新版本arm-linux-gcc-4.4.3進行解壓(注意,如果我們加上了-C,那麼就會自動解壓到/usr/local/arm/這個目錄下),但是友善之臂按照下列方式解壓,不會解壓到/usr/local/arm/目錄下的,這是因為友善之臂把/usr/local/arm/目錄修改成了 /opt/FriendlyARM/toolschain/,除非自己在把它修改過來

[root@localhost ~]# tar -ivxzf /smbroot/arm-linux-gcc-4.4.3.tar.gz  -C /

4,修改配置文件,將arm-linux-gcc添加到環境變量中,因為arm-linux-gcc的命令是在/usr/local/arm/4.4.3/bin下,其目的通過對全局變量綁定使之能夠在任意一個目錄下能夠執行該命令。

打開設置文件

[root@localhost opt]# vi /etc/profile

在打開的文件的

# Path manipulation
if [ "$EUID" = "0" ]; then
        pathmunge /sbin
        pathmunge /usr/sbin
        pathmunge /usr/local/sbin
        pathmunge /usr/local/arm/4.4.3/bin
fi
或者在文件末尾添加

export PATH=$PATH:/usr/local/arm/4.4.3/bin

保存退出

5,立即使新的環境變量生效,不用重啟電腦

[root@localhost opt]#  source /etc/profile

[root@localhost opt]#

6,檢查是否將路徑加入到PATH:

[root@localhost opt]# echo $PATH

顯示的內容中有/usr/local/arm/4.4.3/bin,說明已經將交叉編譯器的路徑加入PATH。至此,交叉編譯環境安裝完成。

7,測試是否安裝成功

首先,執行find命令查詢一下arm-linux-gcc的位置

[root@localhost ~]# find / -name arm-linux-gcc

/opt/arm/toolschain/4.4.3/bin/arm-linux-gcc
[root@localhost ~]#

可以看到arm-linux-gcc的位置與環境變量中設定的路徑一致

接下來查詢arm-linux-gcc的版本

[root@localhost bin]# arm-linux-gcc -v
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /opt/FriendlyARM/mini2440/build-toolschain/working/src/gcc-4.4.3/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=arm-none-linux-gnueabi --prefix=/opt/FriendlyARM/toolschain/4.4.3 --with-sysroot=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --enable-languages=c,c++ --disable-multilib --with-arch=armv4t --with-cpu=arm920t --with-tune=arm920t --with-float=soft --with-pkgversion=ctng-1.6.1 --disable-sjlj-exceptions --enable-__cxa_atexit --with-gmp=/opt/FriendlyARM/toolschain/4.4.3 --with-mpfr=/opt/FriendlyARM/toolschain/4.4.3 --with-ppl=/opt/FriendlyARM/toolschain/4.4.3 --with-cloog=/opt/FriendlyARM/toolschain/4.4.3 --with-mpc=/opt/FriendlyARM/toolschain/4.4.3 --with-local-prefix=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
Thread model: posix
gcc version 4.4.3 (ctng-1.6.1)
[root@localhost bin]#

可以看到arm-linux-gcc的版本號,至此,arm-linu-gcc已成功安裝。

 二,測試

1,在終端中編寫test.c測試程序

[root@localhost ~]# vi test.c
[root@localhost ~]# arm-linux-gcc test.c -o test
/opt/arm/toolschain/4.4.3/bin/../libexec/gcc/arm-none-linux-gnueabi/4.4.3/cc1: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/arm/toolschain/4.4.3/lib/libppl_c.so.2)
/opt/arm/toolschain/4.4.3/bin/../libexec/gcc/arm-none-linux-gnueabi/4.4.3/cc1: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/arm/toolschain/4.4.3/lib/libppl.so.7)
[root@localhost ~]#

用以下命令查看

[root@localhost ~]# strings /usr/lib/libstdc++.so.6|grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_FORCE_NEW
[root@localhost ~]#
可以看到libstdc++.so.6的最高版是GLIBCXX_3.4.8,而不是GLIBCXX_3.4.9,因此需要對libstdc++.so.6進行升級

方法一,參照這篇文章的做法https://wenku.baidu.com/view/ba4f4e222f60ddccda38a01a.html

直接下載較高版本的庫libstdc++.so.6.0.10,網址https://download.csdn.net/source/1670346

先刪除libstdc++.so.6

[root@localhost ~]# rm /usr/lib/libstdc++.so.6

rm:是否刪除 符號鏈接 “/usr/lib/libstdc++.so.6”? y

[root@localhost ~]#

然後將下載的libstdc++.so.6.0.10複製到/usr/lib/目錄下麵

[root@localhost ~]# cp /smbroot/libstdc++.so.6.0.10 /usr/lib/

[root@localhost ~]#

再建立符號鏈接

[root@localhost ~]# ln -s /usr/lib/libstdc++.so.6.0.10 /usr/lib/libstdc++.so.6

[root@localhost ~]#

檢驗是否替換完成

[root@localhost ~]#  strings /usr/lib/libstdc++.so.6|grep GLIBCXX

GLIBCXX_3.4

GLIBCXX_3.4.1

GLIBCXX_3.4.2

GLIBCXX_3.4.3

GLIBCXX_3.4.4

GLIBCXX_3.4.5

GLIBCXX_3.4.6

GLIBCXX_3.4.7

GLIBCXX_3.4.8

GLIBCXX_3.4.9

GLIBCXX_3.4.10

GLIBCXX_FORCE_NEW

GLIBCXX_DEBUG_MESSAGE_LENGTH

[root@localhost ~]#

重新測試交叉編譯是否能用

[root@localhost ~]# arm-linux-gcc test.c -o test

[root@localhost ~]#

編譯成功,執行

[root@localhost ~]# ./test

bash: ./test: cannot execute binary file

[root@localhost ~]

方法二,(參照網上搜來的辦法,還沒嚐試)

下載最新版本glibc-2.13.tar.gz 包含libstdc++.so.6的庫,

然後編譯安裝glibc

wget  https://ftp.gnu.org/gnu/glibc/glibc-2.13.tar.gz

下載glibc-linuxthreads

wget https://ftp.gnu.org/gnu/glibc/glibc-linuxthreads-2.13.tar.gz

解壓

tar -zxvf glibc-2.13.tar.gz

cd glibc-2.13

tar -zxvf ../glibc-linuxthreads-2.3.2.tar.gz

cd ..

./glibc-2.13/configure --prefix=/usr --disable-profile --enable-add-ons --libexecdir=/usr/lib --with-headers=/usr/include

make

make install

注意點:

1、要將glibc-linuxthreads解壓到glibc目錄下。

2、不能在glibc當前目錄下運行configure。

 三、工具使用

1,編譯工具arm-linux-gcc

例如arm-linux-gcc hello.c -o hello

2,反匯編工具arm-linux-gcc

例如arm-linux-objdump -D -S hello

3,elf文件查看工具arm-linux-readelf

arm-linux-readelf  -a hello (查庫所有庫)

arm-linux-readelf -d hello (查看動態鏈接庫)

 

參考文章

https://wenku.baidu.com/view/ba4f4e222f60ddccda38a01a.html

Tekkaman Ninja 博主的文章在Fedora 下建立 ARM-Linux 交叉編譯環境

李白博主的文章crosstool安裝詳解

*****************************************************************************

運行hello : ./hello

  bash: ./hello: cannot execute binary file(無法運行的2進製文件,因為生成的是arm下的2進製文件 );


 

最後更新:2017-04-03 15:21:44

  上一篇:go C# 數據庫係統中使用GDI+繪製柱狀圖
  下一篇:go POJ 3528 & POJ 2974 三維凸包