Json---Linux下使用Jsoncpp

一、安装 scons

  下载地址:http://sourceforge.net/projects/scons/files/scons/2.1.0/scons-2.1.0.tar.gz/download

  百度网盘:链接:https://pan.baidu.com/s/1tW57c9s3iCeoDi4OIDyEPQ 密码:2wd5

  解压:tar -zvxf scons-2.1.0.tar.gz

  进入到解压目录scons-2.1.0 执行命令:

    sudo python setup.py install

 

二、安装 Jsoncpp

  下载地址:http://sourceforge.net/projects/jsoncpp/

  百度网盘:链接:https://pan.baidu.com/s/1tW57c9s3iCeoDi4OIDyEPQ 密码:2wd5

  解压:tar -zvxf jsoncpp-src-0.5.0.tar.gz

  进入到jsoncpp解压目录下,执行命令:

    sudo scons platform=linux-gcc

  将/jsoncpp-src-0.5.0/include/目录下的json文件夹拷贝到 /usr/local/include/

  将jsoncpp-src-0.5.0/libs/linux-gcc-4.9.1/目录下的libjson_linux-gcc-4.9.1_libmt.a 拷贝到 /usr/local/lib/ 下,并为了方便使用,将其重命名为libjson.a

 

三、使用libjson.a 

makefile:

TARGET=main

INC=-I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0/ -I/usr/local/include/json
LIB_PATH=-L/usr/local/lib
LIB=-lmongoc-1.0 -lbson-1.0 /usr/local/lib/libjson.a

CFLAGS:=-Wall -g -O0 -lrt -rdynamic -fPIC -Wl,-rpath=./ $(INC) $(LIB_PATH)
CPPFLAGS:=$(CFLAGS)

SRC=$(shell echo *.cpp)
OBJ=$(patsubst %.cpp,%.o,$(SRC))

all: $(TARGET)

$(TARGET): $(OBJ)
$(CXX) $^ $(CFLAGS) $(LIB) -o $@

clean:
rm -f $(OBJ)
rm -f $(TARGET)

  

json语法 可见:http://www.cnblogs.com/SZxiaochun/p/5866401.html 的 Demo

 

四、编译报错  

error: missing binary operator before token “(“

/usr/include/wchar.h:104:1: error: ‘__BEGIN_NAMESPACE_C99’ does not name a type
/usr/include/wchar.h:107:1: error: ‘__END_NAMESPACE_C99’ does not name a type
/usr/include/wchar.h:135:1: error: ‘__END_NAMESPACE_STD’ does not name a type
/usr/include/wchar.h:149:6: error: expected initializer before ‘__THROW’
/usr/include/wchar.h:153:39: error: expected initializer before ‘__THROW’
/usr/include/wchar.h:157:6: error: expected initializer before ‘__THROW’
/usr/include/wchar.h:161:6: error: expected initializer before ‘__THROW’

/usr/include/c++/4.6/cwchar:143:11: error: ‘::btowc’ has not been declared
/usr/include/c++/4.6/cwchar:144:11: error: ‘::fgetwc’ has not been declared
/usr/include/c++/4.6/cwchar:148:11: error: ‘::fwide’ has not been declared
/usr/include/c++/4.6/cwchar:149:11: error: ‘::fwprintf’ has not been declared
/usr/include/c++/4.6/cwchar:150:11: error: ‘::fwscanf’ has not been declared

/usr/include/c++/4.6/cwchar:215:55: error: invalid conversion from ‘const wchar_t*’ to ‘wchar_t*’ [-fpermissive]
/usr/include/c++/4.6/cwchar:214:3: error:   initializing argument 1 of ‘wchar_t* std::wcschr(wchar_t*, wchar_t)’ [-fpermissive]

/usr/include/locale.h: At global scope:
/usr/include/locale.h:32:1: error: ‘__BEGIN_DECLS’ does not name a type
/usr/include/locale.h:125:65: error: expected initializer before ‘__THROW’
/usr/include/locale.h:128:40: error: expected initializer before ‘__THROW’
/usr/include/locale.h:130:1: error: ‘__END_NAMESPACE_STD’ does not name a type

……

  原因:

    jsoncpp中有一个features.h文件,在/usr/include下也有一个同名的文件,所以就出现文件依赖顺序等问题,一旦搞混,就报了一堆错

  解决方法:

    把jsoncpp的 features.h重命名,然后json.h与reader.h要引用它,在相应的位置换成新的文件名字就ok了。

  

    原文作者:那一剑的风情
    原文地址: https://www.cnblogs.com/SZxiaochun/p/7684454.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞