2012-04-21 106 views
1

我試圖編譯一個示例jsoncpp示例,但是在「標準」頭文件中顯示了大量的編譯錯誤。任何時候有任何機構能看到這個?在編譯jsoncpp示例代碼時需要一些幫助

[~]$ g++ -g -c json.cc -I/usr/local/include/json 
In file included from /usr/include/libio.h:62, 
       from /usr/include/stdio.h:75, 
       from /usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../include/c++/4.4.6/cstdio:45, 
       from json.cc:1: 
/usr/include/sys/cdefs.h:46:44: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:50:44: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:135:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:151:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:209:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:218:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:227:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:236:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:248:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:258:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:267:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:275:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:289:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:297:43: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:326:19: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:338:20: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:343:20: error: missing binary operator before token "(" 
/usr/include/sys/cdefs.h:350:19: error: missing binary operator before token "(" 
In file included from /usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../include/c++/4.4.6/cstring:45, 
       from json.cc:2: 

回答

0

這之類的話,如果你的頭在它之前有一個語法錯誤的一個會發生,如在類聲明的末尾缺少;說。開始清理這些。

1

檢查JSON包含路徑。在編譯選項中使用-I/path of JSON include directory,例如-I$(pkg-config --cflags jsoncpp)

+0

這是問題的原因:從'/ usr/include/json'包含,這樣jsoncpp的'value.h'優先於gcc的''value.h',導致這些確切的錯誤。 – user2394284 2016-05-30 19:07:56

3

對我來說,它是包含在json-cpp中的features.h與系統features.h相沖突的一些其他內容。我在本地將它重命名爲json-cpp代碼中的json_features.h,並且一切正常。

1

您需要包括使用這樣的頭文件: 的#include「JSON/json.h」

1

如果用-I.../include/json編譯,那麼標準庫中可能會意外包含一個JSON頭。 (在這種情況下,根據asuter,它是features.h。)

父目錄是一種頭文件的「名稱空間」。這就是爲什麼任何帶有如incdir/foo/bar.h標題的庫的良好做法是-Iincdir#include <foo/bar.h>