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文件(此文件只对当前用户适用)

扫描二维码关注公众号,回复: 3860097 查看本文章

输入命令:# 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上运行

猜你喜欢

转载自blog.csdn.net/tq576098917/article/details/50346925