Linux搭建交叉编译环境

记录一下搭建嵌入式交叉编译环境的悲惨过程

【WHY】为什么要搭建交叉编译环境呢?

	我本来想在板子arm9(2440)上跑个程序的,但Linux下gcc编译生成的可执行文件,竟然没办法在板子上跑,大概是格式问题吧(说大概是因为自己目前不能百分百确定)。然后了解到要搭建交叉编译环境,要用arm-linux-gcc来编译程序,才能在板子上跑,于是就有了后续这些于是了。

【WHAT】

	使用的交叉工具链是arm-linux-gcc

【HOW】如何搭建呢?

好了,是该进入正题了:
先去官网下载一个arm-linux-gcc安装包,把它放在linux自己中意的目录中,然后解压,解压步骤使用的命令如下。

tar -zxvf arm-linux-gcc-4.4.3.tar.gz 

解压完成,也就代表安装完成了,接下来就是配置系统环境变量,把交叉编译链的路径添加到PATH中,以便在任何路径下可以直接使用arm-linux-gcc这个命令。而在/etc/profile文件中进行配置的话,就相当于永久配置了。所以:
打开/etc/profile文件,在文件末尾加上下面一句

export PATH=$PATH:/root/arm-linux-gcc-4.4.3/FriendlyARM/toolschain/4.4.3/bin

保存后,使用下面命令之一让它立即生效,注意点 . 和 / 之间是有空格的

. /etc/profile
soure /etc/profile

很好,讲道理到这里就可以了吧,一般也就是如此。只是呢,很悲催,我一使用arm-linux-gcc这条命令就出现一堆问题。下面介绍我遇到的这些乱七八糟的问题及其解决方法。
问题1:
/root/arm-linux-gcc-4.4.3/FriendlyARM/toolschain/4.4.3/bin/arm-linux-gcc: /root/arm-linux-gcc-4.4.3/FriendlyARM/toolschain/4.4.3/bin/.arm-none-linux-gnueabi-gcc: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
/root/arm-linux-gcc-4.4.3/FriendlyARM/toolschain/4.4.3/bin/arm-linux-gcc:行15: /root/arm-linux-gcc-4.4.3/FriendlyARM/toolschain/4.4.3/bin/.arm-none-linux-gnueabi-gcc: 成功
解决办法:
yum install ld-linux.so.2

问题2:
/root/arm-linux-gcc-4.4.3/FriendlyARM/toolschain/4.4.3/bin/…/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
解决办法:
[root@localhost arm_linux_gcc_test]# yum list |grep libstdc++.so.6
查看哪个安装包包含该库:
[root@localhost arm_linux_gcc_test]# yum provides libstdc++.so.6
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
libstdc+±4.8.5-16.el7.i686 : GNU Standard C++ Library
源 :rhel7-4
匹配来源:
提供 :libstdc++.so.6
[root@localhost arm_linux_gcc_test]# yum install libstdc+±4.8.5-16.el7.i686

问题3:
[root@localhost arm_linux_gcc_test]# arm-linux-gcc hello.c -o hello
/root/arm-linux-gcc-4.4.3/FriendlyARM/toolschain/4.4.3/bin/…/lib/gcc/arm-none-linux-gnueabi/4.4.3/…/…/…/…/arm-none-linux-gnueabi/bin/as: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
解决方法:
[root@localhost arm_linux_gcc_test]# yum provides libz.so.1
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
zlib-1.2.7-17.el7.i686 : The compression and decompression library
源 :rhel7-4
匹配来源:
提供 :libz.so.1

[root@localhost arm_linux_gcc_test]# yum install zlib-1.2.7-17.el7.i686

[root@localhost arm_linux_gcc_test]# arm-linux-gcc hello.c -o hello
[root@localhost arm_linux_gcc_test]# ls
hello hello.c

总算大功告成!

参照博文:
https://blog.csdn.net/weixin_37985816/article/details/81188865

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值