Linux搭建交叉编译环境

前言:

什么是BuildRoot?

Buildroot is a tool that simplifies and automates the process of building a complete Linux system for an embedded system, using cross-compilation.

In order to achieve this, Buildroot is able to generate a cross-compilation toolchain, a root filesystem, a Linux kernel image and a bootloader for your target. Buildroot can be used for any combination of these options, independently (you can for example use an existing cross-compilation toolchain, and build only your root filesystem with Buildroot).

Buildroot is useful mainly for people working with embedded systems. Embedded systems often use processors that are not the regular x86 processors everyone is used to having in his PC. They can be PowerPC processors, MIPS processors, ARM processors, etc.

Buildroot supports numerous processors and their variants; it also comes with default configurations for several boards available off-the-shelf. Besides this, a number of third-party projects are based on, or develop their BSP [1] or SDK [2] on top of Buildroot.

安装交叉编译依赖 :

sudo apt-get install libncurses5-dev patch

 

下载BuildRoot交叉编译工具:

git clone https://github.com/buildroot/buildroot.git
cd buildroot

      或者直接wget下载:

wget https://buildroot.org/downloads/snapshots/buildroot-snapshot.tar.bz2
tar -xvf buildroot-snapshot.tar.bz2
cd buildroot

 

配置编译选项:

make clean
make menuconfig

    -选择架构: 

     -配置Toolchain

使用uname -a指令查看目标设备的内核版本

配置好之后选择下面的Save选项进行保存。


正式开始编译:

注意编译的过程中需要保持良好的网络连接,因为需要下载一些依赖库。

make -j$(nproc)

最后生成出来mips架构的gcc和g++: 

将编译出来的进行软连接到系统的/usr/bin当中:

ln -s /home/kxd/buildroot/output/host/bin/mipsel-linux-* /usr/bin/

用Cpp写一个helloworld进行测试:

编译命令行:

mipsel-linux-g++ -o ./hello_mips ./hello.cpp -static

file一下看看文件类型 

 

上传到刷过openwrt的mips架构的路由器上 

成功。 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值