首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在windows中使用cJSON

在windows中使用cJSON
EN

Stack Overflow用户
提问于 2019-12-19 22:30:16
回答 3查看 651关注 0票数 1

我想在windows上使用cJSON库和clion。我已经将cJSON.h和cJSON.c复制到我的项目目录中。我已经在这个命令中包含了cJSON.h:#include "cJSON.h“当我试图编译我的项目时,我得到了这些错误:

代码语言:javascript
复制
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
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-12-27 15:11:08

我刚刚解决了这个问题。我唯一需要做的就是将cJSON.h和cJSON.c添加到CMakeLists.txt的add_executable函数中,如下所示:

代码语言:javascript
复制
add_executable(ProjectName main.c cJSON.h cJSON.c)
票数 0
EN

Stack Overflow用户

发布于 2019-12-19 22:58:25

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

票数 0
EN

Stack Overflow用户

发布于 2019-12-19 23:10:09

检查您的CMakeLists.txt文件,在set(SOURCE_FILES)下,如果cJson文件不存在,您应该将其与您自己的文件一起添加。类似于:

代码语言:javascript
复制
set(SOURCE_FILES src/main.cpp include/main.h src/cJson.c include/cJson.h)

如果这样做不起作用,或者它们已经存在,如果您正在尝试将C库与C++一起使用,则可以尝试在括号中包含完整的cJson.h内容来编写extern C {...}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59411762

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档