原创作品,转载请注明出处
copyright:weishusheng 2015.3.18
email:[email protected]
tel:13657214139
平台:
Linux version 2.6.32-279.el6.x86_64
交叉编译器路径:/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
开发板:FL2440
开发板运行内核:linux3.0
开发板文件系统:jffs2
一、准备工作
1.创建fl-easycwmp目录用以存放安装文件
[[email protected] ~]$ mkdir fl-easycwmp
2.创建install目录
[[email protected] ~]$ cd fl-easycwmp/
[[email protected] fl-easycwmp]$ ls
[[email protected] fl-easycwmp]$ mkdir install
[[email protected] fl-easycwmp]$ ls
install
二、交叉编译json-c
1.获取json-c源文件
[[email protected] fl-easycwmp]$ git clone git://github.com/json-c/json-c.git ./json-c
2.创建build.sh
[[email protected] json-c]$ vim build.sh
#!/bin/bash
PRJ_PATH=`pwd`
#CROSS=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-
CROSS=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
make clean
#autoreconf -i
export CC=${CROSS}gcc
export CPP=${CROSS}cpp
export AS=${CROSS}as
export LD=${CROSS}ld
export AR=${CROSS}ar
export RANLIB=${CROSS}ranlib
export STRIP=${CROSS}strip
export ac_cv_func_malloc_0_nonnull=yes
export ac_cv_func_realloc_0_nonnull=yes
export ac_cv_have_decl_isinf=yes
export ac_cv_have_decl_isnan=yes
#export LDFLAGS += -lm
./configure --enable-rdrand --disable-dependency-tracking --with-PACKAGE --with-gnu-ld --with-pic --bu
ild=i686-pc-linux-gnu --host=arm-linux --prefix=${PRJ_PATH}/../install
顺便说一下makefile里cflags的-Wall -o2 -g
-Wall 是打开警告开关,-O代表默认优化,可选:-O0不优化,-O1低级优化,-O2中级优化,-O3高级优化,-Os代码空间优化。
-g是生成调试信息,生成的可执行文件具有和源代码关联的可调试的信息
3.安装json-c
[[email protected] json-c]$ sh build.sh
然后在生成的Makefile里把修改LDFLAGS = -lm,注意每次修改后要make clean(make clean仅仅是清除之前编译的可执行文件及配置文件。 而make distclean要清除所有生成的文件。)
make
make install
三、安装libubox
1、获取libubox
[[email protected] fl-easycwmp]$ git clone git://nbd.name/luci2/libubox.git ./libubox
2.在工程主CMakeLists.txt 中首先加入如下语句:(##注意Linux第一个字母为大写,否则cmake不认识)
[[email protected] libubox]$ vim CMakeLists.txt
SET(CMAKE_SYSTEM_NAME Linux)
SET(TOOLCHAIN_DIR "/opt/buildroot-2012.08/arm920t/usr")
SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_DIR})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY "/home/weishusheng/fl-easycwmp/install/lib/")
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-g++)
SET(CMAKE_INSTALL_PREFIX "/home/weishusheng/fl-easycwmp/install/")
3.生成Makefile
[[email protected] libubox]$ cmake CMakeLists.txt -DBUILD_LUA=OFF
4.make
错误解决:
错误1
/home/weishusheng/fl-easycwmp/libubox/blobmsg_json.c: In function ‘__blobmsg_add_json‘:
/home/weishusheng/fl-easycwmp/libubox/blobmsg_json.c:78:2: error: implicit declaration of function ‘is_error‘
分析:is_error没有定义,在pc上编译时也遇到这个问题,我们知道他的定义为#define is_error(ptr) (ptr == NULL),于是添加定义
[[email protected] libubox]$ vim /home/weishusheng/fl-easycwmp/libubox/blobmsg_json.c
#include "blobmsg.h"
#include "blobmsg_json.h"
#define is_error(ptr) (ptr == NULL)
错误2
cannot find -ljson-c
在CMakeLists.txt里指定json-c库路径
[[email protected] libubox]$ vim CMakeLists.txt
LINK_DIRECTORIES(/home/weishusheng/fl-easycwmp/install/lib/)
错误3
/home/weishusheng/fl-easycwmp/libubox/jshn.c: In function ‘jshn_parse‘:
/home/weishusheng/fl-easycwmp/libubox/jshn.c:162:2: error: implicit declaration of function ‘is_error‘
添加定义
#define is_error(ptr) (ptr == NULL)
4.
/home/weishusheng/cross_easycwmp/install/lib/libjson-c.so: undefined reference to `__isnan‘
/home/weishusheng/cross_easycwmp/install/lib/libjson-c.so: undefined reference to `__isinf‘
这个问题让我抓狂,但你们按我的博客做下来不会出现这个问题,因为我在前面写json-c的安装时为你们解决了,如果有遇到类似问题的,可以尝试在编译json-c时加上
export ac_cv_have_decl_isinf=yes
export ac_cv_have_decl_isnan=yes
并连接上数学库即LDFLAGS+=-lm
四、安装uci
1.获取uci
[[email protected] fl-easycwmp]$ git clone git://nbd.name/uci.git ./uci
2.修改CMakeList.txt
[[email protected] uci]$ vim CMakeLists.txt
SET(CMAKE_SYSTEM_NAME Linux)
SET(TOOLCHAIN_DIR "/opt/buildroot-2012.08/arm920t/usr")
SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_DIR})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-g++)
SET(CMAKE_INSTALL_PREFIX "/home/weishusheng/fl-easycwmp/install/")
cmake_minimum_required(VERSION 2.6)
3.生成makefile
[[email protected] uci]$ cmake CMakeLists.txt -DBUILD_LUA=OFF
4.make
/opt/buildroot-2012.08/arm920t/usr/lib/gcc/arm-unknown-linux-uclibcgnueabi/4.5.4/../../../../arm-unknown-linux-uclibcgnueabi/bin/ld: cannot find -lubox
在CMakeList.txt里加入LINK_DIRECTORIES(/home/weishusheng/fl-easycwmp/install/lib/),问题解决
5.make install
五、安装ubus
1.获取ubus
git clone git://nbd.name/luci2/ubus.git ./ubus
2.修改CMakeList.txt
[[email protected] ubus]$ vim CMakeLists.txt
SET(CMAKE_SYSTEM_NAME Linux)
SET(TOOLCHAIN_DIR "/opt/buildroot-2012.08/arm920t/usr")
SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_DIR})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-g++)
SET(CMAKE_INSTALL_PREFIX "/home/weishusheng/fl-easycwmp/install/")
3.生成makefile
[[email protected] ubus]$ cmake CMakeLists.txt -DBUILD_LUA=OFF
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
json
linked by target "cli" in directory /home/weishusheng/fl-easycwmp/ubus
解决办法:在CMakeList.txt里指定json库路径,通过修改SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)为
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY "/home/weishusheng/fl-easycwmp/install/lib")可解决。
4.make
错误:cannot find -lubox
解决办法:在CMakeLists里加上LINK_DIRECTORIES(/home/weishusheng/fl-easycwmp/install/lib)
错误:json/json.h: No such file or directory
解决办法:交叉编译时默认标准头文件是交叉编译器路径下的,可以用echo ‘main(){}‘|/opt/buildroot-
2012.08/arm920t/usr/bin/arm-linux-gcc -E -v - 命令进行查看,我们把需要用到的头文件加到上诉命令找到的位置就可以
了,另外,交叉编译会到系统默认标准库目录下找库文件,这会导致格式不符合,我们需要用-L及-l指定库文件
[[email protected] json-c]$ pwd
/home/weishusheng/fl-easycwmp/install/include/json-c
[[email protected] json-c]$ sudo mkdir /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-
uclibcgnueabi/sysroot/usr/include/json
[[email protected] json-c]$ sudo cp * /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-
uclibcgnueabi/sysroot/usr/include/json
[[email protected] json-c]$
六、安装microxml
1.获取源文件
[[email protected] fl-easycwmp]$ git clone git://dev.freecwmp.org/microxml ./microxml
2、建立build.sh文件
[[email protected] microxml]$ vim build.sh
#!/bin/bash
PRJ_PATH=`pwd`
#CROSS=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-
CROSS=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
make distclean
autoreconf -i
export CC=${CROSS}gcc
export CPP=${CROSS}cpp
export AS=${CROSS}as
export LD=${CROSS}ld
export AR=${CROSS}ar
export RANLIB=${CROSS}ranlib
export STRIP=${CROSS}strip
./configure --host=arm-linux --prefix=${PRJ_PATH}/../install
make && make install
3.执行
[[email protected] microxml]$ sh build.sh
//七、把shflags.sh放到/usr/share/shflags/目录里
七、最后终于要编译easycwmp了
1.获取源文件
[[email protected] fl-easycwmp]$ wget http://easycwmp.org/download/easycwmp-1.0.5.tar.gz
2.解压,把easycwmp-1.0.5更名为easycwmp并进入该目录
[[email protected] fl-easycwmp]$ cp ../cross_easycwmp/easycwmp-1.0.5.tar.gz .
[[email protected] fl-easycwmp]$ mv easycwmp-1.0.5 easycwmp
[[email protected] fl-easycwmp]$ cd easycwmp
3.生成makefile
[[email protected] easycwmp]$ autoreconf -i
3.生成makefile
[[email protected] easycwmp]$ CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc AR=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar LD=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ld AS=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-as RANLIB=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib CPP=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-cpp ./configure --host=arm-linux --prefix=/home/weishusheng/fl-easycwmp/install MICROXML_CFLAGS="-I/home/weishusheng/fl-easycwmp/install/include -D_THREAD_SAFE -D_REENTRANT" MICROXML_LIBS="-L/home/weishusheng/fl-easycwmp/install/lib -lmicroxml -lpthread" --enable-debug --enable-devel --enable-acs=multi --enable-jsonc=1 --with-uci-include-path=/home/weishusheng/fl-easycwmp/uci/
4.[[email protected] easycwmp]$ make
错误:curl/curl.h: No such file or directory
解决办法:a、先交叉编译curl(下载地址http://curl.haxx.se/download.html),
b、[[email protected] include]$ sudo mkdir /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-
uclibcgnueabi/sysroot/usr/include/curl
c、[[email protected] fl-easycwmp]$ tar -xzf curl-7.41.0.tar.gz
d、vim build.sh
#!/bin/bash
PRJ_PATH=`pwd`
#CROSS=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-
CROSS=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
make distclean
autoreconf -i
export CC=${CROSS}gcc
export CPP=${CROSS}cpp
export AS=${CROSS}as
export LD=${CROSS}ld
export AR=${CROSS}ar
export RANLIB=${CROSS}ranlib
export STRIP=${CROSS}strip
./configure --host=arm-linux --prefix=${PRJ_PATH}/../install
make && make install
e.把头文件复制到相应位置
[[email protected] curl]$ pwd
/home/weishusheng/fl-easycwmp/install/include/curl
[[email protected] curl]$ ls
curlbuild.h curlrules.h easy.h multi.h typecheck-gcc.h
curl.h curlver.h mprintf.h stdcheaders.h
[[email protected] curl]$ sudo cp * /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-uclibcgnueabi/sysroot/usr/include/curl
错误:src/ubus.c:14:21: fatal error: libubus.h: No such file or directory
解决办法:
[[email protected] ubus]$ pwd
/home/weishusheng/fl-easycwmp/ubus
[[email protected] ubus]$ sudo cp libubus.h /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-
uclibcgnueabi/sysroot/usr/include/
错误:ubusmsg.h: No such file or directory
解决办法:
[[email protected] ubus]$ pwd
/home/weishusheng/cross_easycwmp/ubus
[[email protected] ubus]$ sudo cp ubusmsg.h /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-
uclibcgnueabi/sysroot/usr/include/
错误:ubus_common.h: No such file or directory
解决办法:
[[email protected] ubus]$ sudo cp ubus_common.h /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-
uclibcgnueabi/sysroot/usr/include/
错误:src/json.c:42: undefined reference to `is_error‘
解决办法:
vim src/json.c
#define is_error(ptr) (ptr == NULL)
[[email protected] easycwmp]$ make
[[email protected] easycwmp]$ make install
至此easycwmp的交叉编译完成,接下来放到FL2440开发板上跑,在开发板上还要做相关设置,请参考下一遍博文。