Ubuntu 18.04安装i686-elf交叉编译工具链的方法

致谢: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工具链

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值