Issue
I had too many problems with compiling different libraries for json and finally I got an already compiled library of json which is cJSON to be linked with my project but when I downloaded it, and linked it with a test c file like:
//file1.c
#include "cJSON.h"
...
...
...
then I compiled it through gcc using command:
gcc file1.c -lcJSON
it returns:
file1.c:7:19: fatal error: cJSON.h: No such file or directory
#include "cJSON.h"
Solution
Well, finally after several tries I succeed to figure out the problem and fix it. since cJSON is a static library so I can not perform dynamic linking like: -lcJSON
, the perfect way to compile file1.c and link cJSON lib to it, is by:
- Add cJSON.c and cJSON.h files to the same directory of file1.c.
- Include "cJSON.h" in file1.c .
- execute the command
gcc cJSON.c file1.c -lm
.
Finally compilation success.
Answered By - Zainab Answer Checked By - Candace Johnson (WPSolving Volunteer)