分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

Json---Linux下使用Jsoncpp

发布时间:2023-09-06 01:18责任编辑:苏小强关键词:Linux

一、安装 scons

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

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

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

    sudo python setup.py install

二、安装 Jsoncpp

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

  解压: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了。

  

Json---Linux下使用Jsoncpp

原文地址:http://www.cnblogs.com/SZxiaochun/p/7684454.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved