1. 程式人生 > >Json---Linux下使用Jsoncpp

Json---Linux下使用Jsoncpp

expected missing err /usr 語法 namespace can sudo pro

一、安裝 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 [email protected]

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