the correct path to the header library is #include <cjson/cJSON.h>
when installed using the default Makefile configurations.
Also, the compilation command is incorrect, the cJSON library is installed under cjson
in all lowercase. Therefore, use gcc file1.c -lcjson
and it will work.
As @Zainab said, the double quotes "
that surround the file name are when the header file is located inside the same directory as the file you are compiling. The less/greater than symbols <>
are to specify an installed library on the system.
To list installed libraries on your system (assuming you're on a *NIX system, you may run ldconfig -p
). when grepping it with ldconfig -p | grep 'cJSON'
nothing returns on my side, whereas grepping with cjson
does return results:
libcjson_utils.so.1 (libc6,x86-64) => /usr/lib/libcjson_utils.so.1
libcjson_utils.so (libc6,x86-64) => /usr/lib/libcjson_utils.so
libcjson.so.1 (libc6,x86-64) => /usr/lib/libcjson.so.1
libcjson.so (libc6,x86-64) => /usr/lib/libcjson.so
Even more ironically, using the cjson/cjson.h
header file does not work, whereas cjson/cJSON.h
does indeed work.