包含jsoncpp lib时出错

时间:2017-11-06 15:10:14

标签: c++ makefile jsoncpp

我试图用C ++解析JSON。我的Makefile如下所示:

sudo iptables -A INPUT -s 127.0.0.1 -p udp -j ACCEPT

当我只是LDFLAGS = -L/home/ting/Temp/code/jsoncpp/libs/linux-gcc-5.4.0/ ./jsoncpp/libs/linux-gcc-5.4.0/libjson.a ./jsoncpp/libs/linux-gcc-5.4.0/libjson.so INC = -I/home/ting/Temp/code/jsoncpp/include/json CC=g++ CFLAGS = -std=c++11 main: main.cpp $(CC) -o $@ $(LDFLAGS) $(INC) $^ ${CFLAGS} 时,编译器会给我一堆错误。我刚选了一些:

#include "json.h"

它看起来不像libs有任何错误。但只有当我链接到/usr/include/x86_64-linux-gnu/c++/5/bits/os_defines.h:44:19: error: missing binary operator before token "(" #if __GLIBC_PREREQ(2,15) && defined(_GNU_SOURCE) ^ In file included from /usr/include/c++/5/cwchar:44:0, from /usr/include/c++/5/bits/postypes.h:40, from /usr/include/c++/5/iosfwd:40, from /usr/include/c++/5/ios:38, from /usr/include/c++/5/istream:38, from /usr/include/c++/5/fstream:38, from main.cpp:1: /usr/include/wchar.h:74:43: error: missing binary operator before token "(" lib并在Makefile中添加其include dir时才会出现此问题。

我很困惑;发生了什么事?

1 个答案:

答案 0 :(得分:1)

你的jsoncpp包含必须是这样的:

#include <json/json.h>

并且您的包含路径必须以 include 目录结束,这样:

INC = -I/home/ting/Temp/code/jsoncpp/include

如果省略include中的json目录,并将其添加到INC变量中,编译器将最终从json目录中选择 features.h 标题 而不是 glibc 所需的 features.h ,这会产生与您发布的错误类似的错误(请注意,glibc中的features.h定义了 __ GLIBC_PREREQ 宏)。