Ubuntu 18.04安装i686-elf交叉编译工具链的方法[通俗易懂]

Ubuntu 18.04安装i686-elf交叉编译工具链的方法[通俗易懂]一、准备系统:Ubuntu18.04LTS64位Ubuntureleasesgcc7.3.0、g++7.3.0:#切换到超级用户模式,可以Ctrl+D切回普通用户sudo-sadd-apt-repositoryppa:ubuntu-toolchain-r/testapt-getupdateapt-getinstallgcc-7apt-g…

大家好,又见面了,我是你们的朋友全栈君。

致谢:wby大佬
一、准备

系统:Ubuntu 18.04 LTS 64位 Ubuntu releases
gcc 7.3.0、g++ 7.3.0:

# 切换到超级用户模式,可以Ctrl+D切回普通用户
sudo -s
add-apt-repository ppa:ubuntu-toolchain-r/test 
apt-get update
apt-get install gcc-7
apt-get install g++-7
ln -s /usr/bin/gcc-7 /usr/bin/gcc
ln -s /usr/bin/g++-7 /usr/bin/g++

gnu make 4.1:

sudo apt-get install make

二、工具链编译过程

1.下载源代码

# 也可以直接在浏览器下载
wget 'https://ftp.gnu.org/gnu/binutils/binutils-2.30.tar.xz'
wget 'https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.xz'
tar -xvJf binutils-2.30.tar.xz
tar -xvJf gcc-7.3.0.tar.xz

cd gcc-7.3.0
# 该命令会从国外网站下载相关依赖,若无法下载请自行解决网络问题
./contrib/download_prerequisites
cd ..

2.添加环境变量

export PREFIX="/usr/local"
export TARGET=i686-elf

3.编译binutils
什么是binutils?

mkdir build-binutils
cd build-binutils

# 选项说明
# --disable-nls tells binutils not to include native language support. 
  This is basically optional, but reduces dependencies and compile time. 
  It will also result in English language diagnostics.
# --with-sysroot tells binutils to enable sysroot support in the cross-compiler by pointing it to a default empty directory. 
  By default, the linker refuses to use sysroots for no good technical reason, while gcc is able to handle both cases at runtime.
  This will be useful later on.

../binutils-2.30/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make
sudo make install-strip
cd ..

4.编译gcc

mkdir build-gcc
cd build-gcc

# 选项说明
# --disable-nls is the same as for binutils above.
# --without-headers tells GCC not to rely on any C library (standard or runtime) being present for the target.
# --enable-languages tells GCC not to compile all the other language frontends it supports, but only C (and optionally C++).

../gcc-7.3.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
# 注意!下面两条命令会耗费较长时间
make all-gcc
make all-target-libgcc
sudo make install-strip-gcc
sudo make install-strip-target-libgcc
cd ..

若以上过程顺利完成,可以在/usr/local/bin文件夹中看到以i686-elf开头的工具链,下面是我编译好的工具链下载地址,需要请自取:
i686-elf工具链

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/133900.html原文链接:https://javaforall.net

(0)
上一篇 2022年6月7日 下午6:16
下一篇 2022年6月7日 下午6:36


相关推荐

  • LoRaWAN架构简介

    LoRaWAN架构简介LoRaWAN 整体概览 LoRaWAN 协议层次 LoRaWAN 是定义在 LoRa 无线调制技术上的一整套通信协议 类似 TCP IP 协议 LoRaWAN 整个协议的架构图分为几层 绿色的 Application 层是给用户提供数据使用的 主要由用户自己根据需求来进行开发就好 蓝色的 MAC 层是 LoRa 的链接层协议 更详细的内容在 LoRaWAN 标准中可以查看 棕色的 LoRaModulati 对应 OSI 的物理层协议 在具体的应用中 其实就是指 sx127x 或 sx12

    2026年3月26日
    1
  • Fiddler4入门——手机抓包

    Fiddler4入门——手机抓包fiddler手机抓包原理及详细的相关配置

    2022年5月7日
    63
  • javalist集合转换数组_集合对象转数组

    javalist集合转换数组_集合对象转数组问题描述:对于给定的如下数组,如何转换成List集合?String[]array={"a","b","c"};参考stackoverflow总结如下几种写法:1.使用原生方式,拆分数组,添加到ListList<String>resultList=newArrayList<>(array.length);for(Strings:ar…

    2022年8月23日
    9
  • redis默认端口为什么是6379_redis 端口

    redis默认端口为什么是6379_redis 端口1、如果开了redis服务,先将服务关闭2、在window上找到redis的安装目录,修改redis.windows.conf文件,在里面将默认端口改为你想要的端口号3、将redis.windows.conf文件直接拖入redis-server.exe,弹出窗口

    2026年1月16日
    5
  • ASP.NET 状态服务 及 session丢失问题解决方案总结

    ASP.NET 状态服务 及 session丢失问题解决方案总结原文地址:http://www.cnblogs.com/weixing/archive/2009/09/08/session.html十分感谢作者这篇文章ASP.NET2.0系统时,在程序中做删除或创建文件操作时,出现session丢失问题。采用了如下方法:1、asp.netSession的实现:asp.net的Session是基于HttpModule技术做的

    2022年7月15日
    13
  • 史记 乔布斯列传

    史记 乔布斯列传

    2021年8月14日
    114

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号