Ubuntu下建立openwrt-linux交叉编译环境

openwrt是一个linux系统的嵌入式发行版,可以在其上运行程序,但是怎么编译运行在openwrt上的程序呢?由于openwrt没有自带编译器,而且其运行环境的falsh不大,不适合在嵌入式设备上安装编译器,故需要openwrt-linux的交叉编译环境。下面来说说linux安装交叉编译环境的方法:
1.安装依赖包:

Ubuntu 13.10:

sudo apt-get install build-essential subversion git-core libncurses5-dev zlib1g-dev gawk flex quilt xsltproc

Ubuntu 12.04LTS:

sudo apt-get install build-essential subversion git-core libncurses5-dev zlib1g-dev gawk  flex quilt libssl-dev xsltproc 
libxml-parser-perl mercurial bzr ecj cvs unzip

Ubuntu 64bit:

sudo apt-get install build-essential subversion libncurses5-dev zlib1g-dev gawk gcc-multilib flex git-core gettext

2.从openwrt官网上下载编译工具

https://downloads.openwrt.org/

或在终端执行(这里选择的时MT7620A的CPU)

wget https://downloads.openwrt.org/barrier_breaker/14.07/ramips/mt7620n/OpenWrt-Toolchain-ramips-for-mipsel_24kec%2bdsp-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2

然后解压文件

tar -xjf OpenWrt-Toolchain-ramips-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2

然后进入目录

cd OpenWrt-Toolchain-ramips-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin

可以看到很多工具如下:
这里写图片描述
3.修改环境变量。

终端输入

sudo gedit ~/.bashrc

输入密码,然后在打开的文件的末尾添加下面的代码:

PATH=$PATH:/path/OpenWrt-Toolchain-ramips-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin
export PATH

export STAGING_DIR=/path/OpenWrt-Toolchain-ramips-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2
export PATH=$PATH:$STAGING_DIR/bin

注意,这里的path必须修改为你的安装目录。
然后使环境变量有效就行了

source ~/.bashrc

4.到这里已经可以使用交叉编译工具了,如:

mipsel-openwrt-linux-gcc -c hello.c -o hello

5.这里编译出的hello已经可以在openwrt上运行了。

猜你喜欢

转载自blog.csdn.net/gaoyang8320/article/details/51147916
今日推荐