easycwmp的交叉编译

easycwmp的交叉编译

来源:网络    编辑:admin

 

平台:

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目录用以存放安装文件

[weishusheng@localhost ~]$ mkdir fl-easycwmp

 

2.创建install目录

[weishusheng@localhost ~]$ cd fl-easycwmp/
[weishusheng@localhost fl-easycwmp]$ ls
[weishusheng@localhost fl-easycwmp]$ mkdir install
[weishusheng@localhost fl-easycwmp]$ ls
install

二、交叉编译json-c

1.获取json-c源文件

[weishusheng@localhost fl-easycwmp]$ git clone git://github.com/json-c/json-c.git ./json-c

 

2.创建build.sh

[weishusheng@localhost 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

[weishusheng@localhost json-c]$ sh build.sh 

然后在生成的Makefile里把修改LDFLAGS = -lm,注意每次修改后要make clean(make clean仅仅是清除之前编译的可执行文件及配置文件。 而make distclean要清除所有生成的文件。)

make

make install

 

三、安装libubox

1、获取libubox

[weishusheng@localhost fl-easycwmp]$ git clone git://nbd.name/luci2/libubox.git ./libubox

2.在工程主CMakeLists.txt 中首先加入如下语句:(##注意Linux第一个字母为大写,否则cmake不认识)

[weishusheng@localhost 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

[weishusheng@localhost 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),于是添加定义

[weishusheng@localhost 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库路径

[weishusheng@localhost 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

[weishusheng@localhost fl-easycwmp]$ git clone git://nbd.name/uci.git ./uci  

 

2.修改CMakeList.txt

[weishusheng@localhost 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

[weishusheng@localhost 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

[weishusheng@localhost 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

[weishusheng@localhost 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指定库文件

[weishusheng@localhost json-c]$ pwd
/home/weishusheng/fl-easycwmp/install/include/json-c
[weishusheng@localhost json-c]$ sudo mkdir /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-
uclibcgnueabi/sysroot/usr/include/json
[weishusheng@localhost json-c]$ sudo cp * /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-
uclibcgnueabi/sysroot/usr/include/json
[weishusheng@localhost json-c]$

 

六、安装microxml

1.获取源文件

[weishusheng@localhost fl-easycwmp]$ git clone git://dev.freecwmp.org/microxml ./microxml

 

2、建立build.sh文件

[weishusheng@localhost 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.执行

[weishusheng@localhost microxml]$ sh build.sh

 

//七、把shflags.sh放到/usr/share/shflags/目录里

 

七、最后终于要编译easycwmp了

1.获取源文件

[weishusheng@localhost fl-easycwmp]$ wget http://easycwmp.org/download/easycwmp-1.0.5.tar.gz

 

2.解压,把easycwmp-1.0.5更名为easycwmp并进入该目录

[weishusheng@localhost fl-easycwmp]$ cp ../cross_easycwmp/easycwmp-1.0.5.tar.gz .

[weishusheng@localhost fl-easycwmp]$ mv easycwmp-1.0.5 easycwmp
[weishusheng@localhost fl-easycwmp]$ cd easycwmp

 

3.生成makefile

[weishusheng@localhost easycwmp]$ autoreconf -i

 

3.生成makefile

[weishusheng@localhost 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.[weishusheng@localhost easycwmp]$ make

 

错误:curl/curl.h: No such file or directory

解决办法:a、先交叉编译curl(下载地址http://curl.haxx.se/download.html),

       b、[weishusheng@localhost include]$ sudo mkdir /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux- 

uclibcgnueabi/sysroot/usr/include/curl

               c、[weishusheng@localhost 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.把头文件复制到相应位置          

               [weishusheng@localhost curl]$ pwd
               /home/weishusheng/fl-easycwmp/install/include/curl
               [weishusheng@localhost curl]$ ls
               curlbuild.h curlrules.h easy.h multi.h typecheck-gcc.h
               curl.h curlver.h mprintf.h stdcheaders.h

               [weishusheng@localhost 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
解决办法:

[weishusheng@localhost ubus]$ pwd
/home/weishusheng/fl-easycwmp/ubus
[weishusheng@localhost 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
解决办法:

[weishusheng@localhost ubus]$ pwd
/home/weishusheng/cross_easycwmp/ubus

[weishusheng@localhost 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

解决办法:

[weishusheng@localhost 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)

 

[weishusheng@localhost easycwmp]$ make 

[weishusheng@localhost easycwmp]$ make install

 

From: http://www.cnblogs.com/wss-linux/p/4348888.html

你可能感兴趣的:(编译)