我正在尝试编译一个示例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 :(得分:4)
对我而言,json-c ++中包含的features.h与其他一些包含的系统features.h冲突。我在json-cpp代码中将它本地重命名为json features.h,一切都很顺利。
答案 1 :(得分:1)
检查JSON包含路径。在编译选项中使用-I/path of JSON include directory
,例如-I$(pkg-config --cflags jsoncpp)
。
答案 2 :(得分:1)
您需要使用以下方式包含头文件: #include“json / json.h”
答案 3 :(得分:1)
如果使用-I.../include/json
进行编译,则标准库可能会意外地包含JSON标头。 (在这种情况下,根据asuter,它是features.h
。)
父目录是头文件的一种“命名空间”。这就是为什么任何带有incdir/foo/bar.h
标题的库的良好做法是-Iincdir
和#include <foo/bar.h>
。
答案 4 :(得分:0)
如果在其前面的一个标头在类声明结束时出现语法错误(例如缺少;
),则会发生这种情况。首先要清理它们。