1、下载openwrt源码编译
貌似版本很多,也不是所有版本都适合我的板子,所以这点得弄清楚。我下得是barrier_break,支持mt7620a开发板。按照上面的教程,把该准备的给准备着,具体总结如下:
1.1 目前有三种,v12.09,attitude adjustment,barrier_breaker,貌似中间第二种不支持mt7620
1.2 将下面某一行添加进对应版本的feeds.conf
src-git alljoyn https://git.allseenalliance.org/gerrit/core/openwrt_feed;openwrt_12.09
src-git alljoyn https://git.allseenalliance.org/gerrit/core/openwrt_feed;barrier_breaker
1.3 更新和安装
./scripts/feeds update -a
./scripts/feeds install -a -p alljoyn
1.4 make menuconfig时按照下图选择
当然如果选择模块,则生成ipk文件,如果集成到内核中,则直接刷固件就有了
我们可以在build_dir/target-mipsel-24kec**/下找到alljoyn的相关目录,里面的build目录下有生成好的库和二进制文件
2、编写alljoyn程序
编译方法和helloworld类似了,我前篇博文有讲述,这里就不说了,我主要列出src文件夹的makefile
3、交叉编译
在sdk顶层下编译程序,成功后在build_dir/target**/ajtest/下有执行程序,scp到板子上运行。这里截取一下交叉编译器的编译和链接过程,注意观察用到了哪些目录下的头文件目录和库目录
【编译】
mipsel-openwrt-linux-uclibc-g++ -os -pipe -mno-branch-likely -mips32r2 -mtune=24kec -mdsp -fno-caller-saves -fhonour-copts -wno-error=unused-but-set-variable
-msoft-float -i/home/cshi/download/openwrt/barrier_breaker/bin/ramips/openwrt-sdk-ramips-for-linux-i686-gcc-4.8-linaro_uclibc-0.9.33.2/staging_dir/target-mipsel_24kec+dsp_uclibc-0.9.33.2/usr/include
-i/home/cshi/download/openwrt/barrier_breaker/bin/ramips/openwrt-sdk-ramips-for-linux-i686-gcc-4.8-linaro_uclibc-0.9.33.2/staging_dir/target-mipsel_24kec+dsp_uclibc-0.9.33.2/include-i/home/cshi/download/openwrt/barrier_breaker/bin/ramips/openwrt-sdk-ramips-for-linux-i686-gcc-4.8-linaro_uclibc-0.9.33.2/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uclibc-0.9.33.2/usr/include
-i/home/cshi/download/openwrt/barrier_breaker/bin/ramips/openwrt-sdk-ramips-for-linux-i686-gcc-4.8-linaro_uclibc-0.9.33.2/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uclibc-0.9.33.2/include -c
hello.cpp
【链接】
mipsel-openwrt-linux-uclibc-g++ -l/home/cshi/download/openwrt/barrier_breaker/bin/ramips/openwrt-sdk-ramips-for-linux-i686-gcc-4.8-linaro_uclibc-0.9.33.2/staging_dir/target-mipsel_24kec+dsp_uclibc-0.9.33.2/usr/lib
-l/home/cshi/download/openwrt/barrier_breaker/bin/ramips/openwrt-sdk-ramips-for-linux-i686-gcc-4.8-linaro_uclibc-0.9.33.2/staging_dir/target-mipsel_24kec+dsp_uclibc-0.9.33.2/lib -l/home/cshi/download/openwrt/barrier_breaker/bin/ramips/openwrt-sdk-ramips-for-linux-i686-gcc-4.8-linaro_uclibc-0.9.33.2/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uclibc-0.9.33.2/usr/lib
-l/home/cshi/download/openwrt/barrier_breaker/bin/ramips/openwrt-sdk-ramips-for-linux-i686-gcc-4.8-linaro_uclibc-0.9.33.2/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uclibc-0.9.33.2/lib hello.o
-o hello
4、保证板中已经有了liballjoyn,pthread,librt,ssl等库,且正确设置了动态库路径,执行即可
用ldd检查可发现加载了哪些动态库
【插曲一】
从官方路径中下载的libstdcpp貌似不管用,害得整半天,在执行alljoyn程序时,出现如下错误:
经查询发现它在c++文件hashtable_c++0x.o中
再对比barrier_breaker上的cpp库(libstdc++.so.6.0.19)和板子上的cpp库(libstdc++.so.6.0.16),发现后者小很多且nm不到任何符号,不如直接替换,让软链接libstdc++.so.6指向19版本,看看能不能找到这个符号,果然可以了。
【插曲二】
符号找到了,却识别不了我pc上的客户端了。大胆猜测一下,是不是板子上的防火墙阻挡了?一试,果然是!
正如上图所示,由于我将板子连入了另外一个接入外网的路由器,产生了wan区域,将其入口设置为接受即可,这样,板子上的alljoyn服务端就可识别pc上的客户端了(当然要在同一个局域网内啦)
参考链接