编译jshon,需要提前编一个jansson库,他是jshon依赖的。
先总结一下,编译时候遇到的问题。
编译参数配置错误
kebo@6fecdc70e5b2:~/jansson-2.12$ ./configure --build=arm-linux --host=arm-xxxx-gnueabihf-gcc --target=arm-xxxx-gnueabihf-gcc
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-linux-gnueabihf-gcc-strip... no
checking for strip... strip
configure: WARNING: using cross tools not prefixed with host triplet
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for arm-linux-gnueabihf-gcc-gcc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
checking build system type... arm-unknown-linux-gnu
checking host system type... Invalid configuration `arm-xxxx-gnueabihf-gcc': machine `arm-xxxx-gnueabihf' not recognized
configure: error: /bin/bash ./config.sub arm-xxxx-gnueabihf-gcc failed
kobe@6fecdc70e5b2:~/jansson-2.12$
还有类是下面的命令都是错误的
./configure --build=arm --host=arm-xxxx-gnueabihf-gcc --target=arm-xxxx-gnueabihf-gcc
./configure --build=arm --host=arm-xxxx-gnueabihf-gcc
./configure --prefix=`pwd`/release CC=arm-xxx-linux-gcc CXX=arm-xxx-linux-g++ --host=arm-linux
如果上面你基本都试过了,那么你很快也就编译出来了。执行下面命令。
./configure CC=arm-xxxx-gnueabihf-gcc CXX=arm-xxxx-gnueabihf-g++
详细步骤如下:
1、下载源码
sles10:~ # wget http://kmkeen.com/jshon/jshon.tar.gz
sles10:~ # wget http://www.digip.org/jansson/releases/jansson-2.12.tar.gz
sles10:~ # tar -xzf jshon.tar.gz; tar -xzf jansson-2.12.tar.gz
2、设置编译环境
因为交叉编译,因此需要把工具链的安装路径添加到$PATH中,这样保证编译工具能被找到。
export PATH=/home/kobe/gcc/arm/gcc-x86_64_arm-xxxx-gnueabihf/bin/:$PATH
其中/home/kobe/gcc/arm/gcc-x86_64_arm-xxxx-gnueabihf/bin/是交叉编译工具目录,具体路径根据自己实际情况设置。
3、编译
sles10:~ # cd jansson-2.12
sles10:~ # ./configure CC=arm-xxxx-gnueabihf-gcc CXX=arm-xxxx-gnueabihf-g++ CC_LD=arm-linux-gnueabihf-ld --host=arm-linux
sles10:~# make
这里编译成功。
sles10:~/jansson-2.12 # cp src/jansson.h ../jshon-20120914/
sles10:~/jansson-2.12 # cp src/jansson_config.h ../jshon-20120914/
sles10:~/jansson-2.12 # ls -ltr src/.libs
total 576
-rw-r--r-- 1 root root 6592 Feb 28 08:31 utf.o
-rw-r--r-- 1 root root 23124 Feb 28 08:36 dump.o
-rw-r--r-- 1 root root 7228 Feb 28 08:36 memory.o
-rw-r--r-- 1 root root 37192 Feb 28 08:36 load.o
-rw-r--r-- 1 root root 6472 Feb 28 08:36 hashtable_seed.o
-rw-r--r-- 1 root root 21084 Feb 28 08:36 hashtable.o
-rw-r--r-- 1 root root 7656 Feb 28 08:36 error.o
-rw-r--r-- 1 root root 47160 Feb 28 08:36 value.o
-rw-r--r-- 1 root root 7944 Feb 28 08:36 strconv.o
-rw-r--r-- 1 root root 7708 Feb 28 08:36 strbuffer.o
-rw-r--r-- 1 root root 35296 Feb 28 08:36 pack_unpack.o
-rw-r--r-- 1 root root 1302 Feb 28 08:36 libjansson.ver
-rwxr-xr-x 1 root root 149076 Feb 28 08:36 libjansson.so.4.11.1
lrwxrwxrwx 1 root root 20 Feb 28 08:36 libjansson.so.4 -> libjansson.so.4.11.1
lrwxrwxrwx 1 root root 20 Feb 28 08:36 libjansson.so -> libjansson.so.4.11.1
-rw-r--r-- 1 root root 949 Feb 28 08:36 libjansson.lai
lrwxrwxrwx 1 root root 16 Feb 28 08:36 libjansson.la -> ../libjansson.la
-rw-r--r-- 1 root root 1206 Feb 28 08:36 libjansson.exp
-rw-r--r-- 1 root root 197868 Feb 28 08:36 libjansson.a
sles10:~/jansson-2.12 # cp -p src/.libs/libjansson.so* ../jshon-20120914/
sles10:~/jansson-2.12 # cd ../jshon-20120914
sles10:~/jshon-20120914 # sed -i '/include/s//"jansson.h"/' jshon.c
sles10:~/jshon-20120914 # ls
Makefile jansson.h jansson_config.h jshon jshon.1 jshon.c libjansson.so libjansson.so.4 libjansson.so.4.11.1
sles10:~/jshon-20120914 #arm-linux-gnueabihf-gcc jshon.c -ljansson -o jshon -L./
4、最终结果
6fecdc70e5b2:~/jshon/jshon-20120914$ ls
Makefile jansson.h jansson_config.h jshon jshon.1 jshon.c libjansson.so libjansson.so.4 libjansson.so.4.11.1
jshon的二进制文件就是最终编译结果。
参考:
https://www.claudiokuenzler.com/blog/935/installing-compiling-jshon-jansson-old-linux-sles-10