I want to use cJSON library on windows with clion. I have copied cJSON.h and cJSON.c to my project directory. I have included cJSON.h with this command: #include "cJSON.h" When I try to compile my project, I get these errors:
CMakeFiles\Client.dir/objects.a(main.c.obj): In function `parse':
.../main.c:117: undefined reference to `cJSON_Parse@4'
.../main.c:121: undefined reference to `cJSON_GetErrorPtr@0'
.../main.c:127: undefined reference to `cJSON_GetObjectItemCaseSensitive@8'
.../main.c:128: undefined reference to `cJSON_GetObjectItemCaseSensitive@8'
.../main.c:131: undefined reference to `cJSON_IsString@4'
.../main.c:131: undefined reference to `cJSON_IsString@4'
.../main.c:141: undefined reference to `cJSON_Delete@4'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\Client.dir\build.make:84: recipe for target 'Client.exe' failed
mingw32-make.exe[3]: *** [Client.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Client.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Client.dir/rule] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/Client.dir/all' failed
CMakeFiles\Makefile2:83: recipe for target 'CMakeFiles/Client.dir/rule' failed
Makefile:117: recipe for target 'Client' failed
mingw32-make.exe: *** [Client] Error 2
I just solved the problem. The only thing I needed to do was to add cJSON.h and cJSON.c to the add_executable function of CMakeLists.txt like this:
add_executable(ProjectName main.c cJSON.h cJSON.c)