錯誤產生
安裝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/