centos arm linux gcc,CentOS安装arm-linux-gcc交叉编译器
(注:首先需要明確需要安裝centos系統的位數,即是32位的還是64位的。)
1、下載并解壓文件:下載arm-linux-gcc-4.4.3.tgz到任意的目錄下,進入這個文件夾
輸入命令:# tar xvzf arm-linux-gcc-4.4.3.tgz –C / ?【解壓文件到 /opt/Friendlyarm/4.4.3 目錄】
注意:C后面有個空格,并且C是大寫的,它是英文單詞“Change”的第一個字母,
在此是改變目錄的意思。
在/usr/local/下建立arm的文件夾
輸入命令:# mkdir arm ?【新建 /usr/local/arm/ 目錄】
# chmod 777 arm ?【修改此文件夾的權限 ,可用 命令 # cd -ll 查看】
輸入命令:# cp -r /opt/Friendlyarm/4.4.3 /usr/local/arm/ 【然后把opt下的4.4.3目錄復制到/usr/local下】
2、修改環境變量,把交叉編譯器的路徑加入到PATH。
方法一:修改/etc/bash.bashrc文件(此文件只對當前用戶適用)
輸入命令:# gedit /etc/bash.bashrc
在最后加上 ? ?export PATH=$PATH:/usr/local/arm/4.4.3/bin
方法二(推薦):修改/etc/profile文件(此文件屬于系統級別的環境變量,設置在里面的東西對所有用戶適用):
輸入命令:# vim /etc/profile
增加路徑設置,在末尾添加如下,保存/etc/profile文件:
export PATH=$PATH:/usr/local/arm/4.4.3/bin
方法三:修改/etc/environm:ent文件
輸入命令:# gedit /etc/environment
原文件應為 ?PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin: /usr/games“
將其改為 ? ? ?PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/arm/4.4.3/bin"
保存退出即可
關于路徑設置問題,可以 用終端逐步尋找,比如 在 終端下cd /usr/local/用TAB鍵 一直找到/bin
關于環境變量問題:
環境變量是什么?例如path,當要求系統運行一個程序而沒有告訴它程序所在的完整路徑時,系統除了在當前目錄下面尋找此程序外,還應到path中指定的路徑去找。用戶通過設置環境變量,來更好的運行進程。
如果上面不加入環境變量,要運行arm-linux-gcc這個程序,則每次都要把arm-linux-gcc的完整路徑寫出來。/usr/local/arm/4.4.3/bin arm-linux-gcc文件名-o輸出文件名
這樣非常的麻煩,所以加到path里面,讓電腦知道這個程序在哪里。
3. 立即使新的環境變量生效,不用重啟電腦:
對應方法一:
輸入命令:# source /root/.bashrc
對應方法二:
輸入命令:# source /etc/profile
方法三立即生效
4. 檢查是否將路徑加入到PATH:
輸入命令:#echo $PATH
顯示內容/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/arm/4.4.3/bin說明已經將交叉編譯器的路徑加入PATH。至此,交叉編譯環境安裝完成。
5.測試是否安裝成功
輸入命令:#arm-linux-gcc -v
若centos為32位系統則會直接安裝成功,則會顯示如下信息:
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)
若centos系統為64位時,則會提示一下內容
/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
表示沒有安裝成功,此時則需要做如下操作:
1、在64系統里執行32位程序如果出現/lib/ld-linux.so.2:
bad ELF interpreter: No such file or directory,安裝下glic即可
則需要
輸入命令:# yum install glibc.i686
【 www.2cto.com ?】
2、如果出現error while loading shared libraries: libz.so.1:
cannot open shared object file: No such file or directory
則需要
輸入命令:#
yum install zlib.i686
3、如果出現/libexec/gcc/arm-none-linux-gnueabi/4.4.3/cc1:
error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
則需要
輸入命令:#
yum -y install libstdc*
另外若當有缺少共享庫的報錯:
error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
解決辦法:
1、輸入命令:# yum whatprovides libstdc++.so.6
然后會提示哪個安裝包有這個庫文件如下:
[root@localhost ~]# yum whatprovides libstdc++.so.6
Loaded plugins: aliases, changelog, downloadonly, fastestmirror, kabi, presto, refresh-packagekit, security, tmprepo, verify,
: versionlock
Loading support for CentOS kernel ABI
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* centosplus: centos.ustc.edu.cn
* contrib: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
libstdc++-4.4.7-3.el6.i686 : GNU Standard C++ Library
Repo? ? ? ? : base
Matched from:
Other? ? ? : libstdc++.so.6
2、然后執行:
輸入命令:# yum install libstdc++-4.4.7-3.el6.i686
搞定!
6.編譯Hello World程序,測試交叉工具鏈
寫下下面的Hello World程序,保存為hello.c
#include “stdio.h”
int main()
{
printf("Hello World!\n");
return 0;
}
執行下面的命令:
$ arm-linux-gcc hello.c -o hello
ls下
看到hello執行文件
$ file hello在hello的目錄下
可以看到hello: ELF 32-bit LSB executable,ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, not stripped
這樣說明可以在ARM上運行,此時不能在pc上運行
總結
以上是生活随笔為你收集整理的centos arm linux gcc,CentOS安装arm-linux-gcc交叉编译器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java暂停另一个线程_如何从另一个线程
- 下一篇: 广州计算机操作员培训,汕尾市计算机操作员