经常需要自己给Openwrt编译点什么玩玩,这时候就需要用到SDK了。 一般网上给出的方法都是写一个Makefile然后构建的。比如我之前的文章。我这个人比较懒,所以想直接使用里面交叉编译器来编译东西。
tar -xvf OpenWrt-SDK-15.05.1-ramips-mt7620_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2 ```
mv OpenWrt-SDK-15.05.1-ramips-mt7620_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/ openwrt/ ```
cd openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin
看一下交叉编译工具的前缀bash
ls *g++
```
我这里显示是这样的
> mipsel-openwrt-linux-uclibc-g++
> mipsel-openwrt-linux-g++
可以看出前缀就是mipsel啦。为了方便,我们设置多一个环境变量(不同架构记得替换里面的mipsel哦):
```bash
architecture=mipsel ```
设置环境变量
PATH=$PATH:$(pwd) cd .. STAGING_DIR=$(pwd) export PATH export STAGING_DIR
6. 环境配置好就可以开始编译啦
我这里用`isatapd`示范一下编译
首先下载源码,并且进入源码目录
```bash
wget http://www.saschahlusiak.de/linux/isatapd-0.9.7.tar.gz
tar -xvf isatapd-0.9.7.tar.gz
cd isatapd-0.9.7/
```
7. 对源码进行configure
```bash
./configure --build=${architecture}-unknown-linux-gnu -host=${architecture}-openwrt-linux-uclib
```
很快就configure完成了
8. 然后就是make了
```bash
make
不configure直接make 有时候有的项目是没有configure脚本生辰Makefile的,而是直接有几个Makefile给你挑选make的。这时候如果要直接make的话,要设置自己的编译工具:
make CC=${architecture}-openwrt-linux-uclibc-gcc LD=${architecture}-openwrt-linux-uclibc-ld CXX=${architecture}-openwrt-linux-uclibc-g++ ```
似乎有点问题
我直接make之后,报错了:
mipsel-openwrt-linux-uclibc-gcc -Wall -g -O2 -o isatapd main.o isatap.o tunnel.o rdisc.o
main.o: In function 'add_router_to_name_list': /home/lovesy/isatapd/src/main.c:134: undefined reference to 'rpl_malloc' isatap.o: In function 'new_internal_pdr': /home/lovesy/isatapd/src/isatap.c:70: undefined reference to 'rpl_malloc' collect2: error: ld returned 1 exit status
看来是configure脚本的时候给我弄了个rpl_malloc作为内存分配函数。但是Openwrt SDK应该是没有这玩意儿的。追溯源码,修改config.h文件,把里面的#define malloc rpl_malloc删掉就好了。
重新编译一下
make clean && make ``` 这下就成功编译好了。把src/isatapd拿出来放到路由器里面执行就好了。
粤公网安备44030002005029号