使用openwrt难免需要编译自己的c或者C++程序,所以我们需要搭建自己的交叉编译环境
(1)在生成Openwrt固件时,选择Buildthe OpenWrt based Toolchain和Build the OpenWrt SDK就可以生成相应的交叉编译器。如下图所示:
(2)找到trunk/bin/ramips/OpenWrt-Toolchain-ramips-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2
并将其拷贝到交叉编译的机器上
(3)解压到某个目录,例如/usr/share/openwrt
tar xvfOpenWrt-Toolchain-ramips-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2-C /usr/share/openwrt
(4)建立软链接,对应关系如下:
/usr/bin/mips-g++ ->/usr/share/openwrt/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/mipsel-openwrt-linux-g++
/usr/bin/mips-gcc ->/usr/share/openwrt/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/mipsel-openwrt-linux-gcc
/usr/bin/mips-strip ->/usr/share/openwrt/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/mipsel-openwrt-linux-strip
(5)找到
trunk/bin/ramips/OpenWrt-SDK-ramips-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2
(6)解压到某个目录,例如/home/huqian/build/OpenWrt-SDK-ramips-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2
/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2
并执行
exportSTAGING_DIR=/home/xxxx/build/OpenWrt-SDK-ramips-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2
接下来,就可以直接使用mips-g++/mips-gcc命令来编译可以在Openwrt上运行的程序。