错误产生
安装json-c库之后,根据GitHub上面的readme文件链接到json-c库时出现以下错误:
SDMBNJson.h:9:23: fatal error: json/json.h: No such file or directory
#include <json/json.h>
^
compilation terminated.
贴出readme:
Linking to `libjson-c`
----------------------
If your system has `pkgconfig`,
then you can just add this to your `makefile`:
\```make
CFLAGS += $(shell pkg-config --cflags json-c)
LDFLAGS += $(shell pkg-config --libs json-c)
```
Without `pkgconfig`, you would do something like this:
\```make
JSON_C_DIR=/path/to/json_c/install
CFLAGS += -I$(JSON_C_DIR)/include/json-c
LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c
\```
可是,按照readme上面的做法还是无法解决问题。
解决方案
在Linux系统中,/usr/include/ 是C/C++等的头文件放置处,当使用源代码方式安装某些数据时,会使用到其中很多文件。因此将编译安装完成的json-c文件夹改名为“json”放在/usr/include/目录下,即可解决:
cd /usr/include
sudo mkdir json
sudo cp /usr/local/include/json-c/* /usr/include/json/