在Windows中使用cJSON

问题描述 投票:0回答:1

我想在带有clion的Windows上使用cJSON库。我已将cJSON.h和cJSON.c复制到我的项目目录中。我在此命令中包含了cJSON.h:#include“ cJSON.h”当我尝试编译我的项目时,出现以下错误:

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
c json cjson
1个回答
0
投票

[好像您没有将cjson.c文件添加到构建中,这会导致链接错误,或者您可能将c文件(cjson.c)添加到c ++项目,并且您缺少'extern C'前缀您的cjson.h标头。

© www.soinside.com 2019 - 2024. All rights reserved.