1

我正在尝试编译一个示例 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:
4

5 回答 5

4

For me it was the features.h included with json-cpp conflicting with the system features.h in some other includes. I renamed it locally to json_features.h in the json-cpp code and all was well.

于 2013-04-27T01:34:56.303 回答
1

检查 JSON 包含路径。在编译选项中使用-I/path of JSON include directory,例如-I$(pkg-config --cflags jsoncpp)

于 2013-04-08T23:14:50.467 回答
1

您需要使用这种方式包含头文件:#include "json/json.h"

于 2014-04-29T10:08:09.123 回答
1

如果使用 编译-I.../include/json,则标准库可能会意外包含 JSON 标头。(在这种情况下,根据 asuter 的说法,它是features.h.)

父目录是头文件的一种“命名空间”。这就是为什么任何带有像incdir/foo/bar.his-Iincdir#include <foo/bar.h>.

于 2015-02-16T23:40:18.820 回答
0

如果您之前的一个标题有语法错误,例如;在类声明末尾丢失,就会发生这种情况。从清理那些开始。

于 2012-05-24T01:06:38.817 回答