I am trying to compile a sample jsoncpp example, but there are tons of compiling errors showing up in "standard" headers. did any body see this any time ?
[~]$ 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:
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.
You need to include header file using this way: #include "json/json.h"
If you compile with -I.../include/json
, then the standard library might accidentally include a JSON header. (In this case, according to asuter, it was features.h
.)
The parent directory is a kind of "namespace" for header files. That's why a good practice for any library with headers like incdir/foo/bar.h
is -Iincdir
and #include <foo/bar.h>
.
Check JSON include path. In compilation option use -I/path of JSON include directory
, e.g. -I$(pkg-config --cflags jsoncpp)
.
That's the kind of thing that would happen if one of your headers that preceded it had a syntax error such as a missing ;
at end of class declaration. Start by cleaning those.
来源:https://stackoverflow.com/questions/10256476/need-some-help-in-compiling-a-jsoncpp-sample-code