gpt4 book ai didi

c++ - 包含 jsonCpp header 的问题

转载 作者:太空狗 更新时间:2023-10-29 20:06:59 24 4
gpt4 key购买 nike

我试图在我的 C++ 代码中实现 jsoncpp 库,我写了一段简单的代码只是为了尝试一下,它甚至没有编译。

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>

#ifndef json_included
#define json_included
#include "jsoncpp\include\json\json.h"
#endif

//#include "json\jsonC\json.h"
int main(int argc, char **argv)
{

std::string example = "{\"array\":[\"item1\", \"item2\"], \"not an array\":\"asdf\"}";
Json::Value value;
Json::Reader reader;

bool parsed = reader.parse(example, value, false);
std::cout << parsed;
return 0;
}

我得到的错误是:

undefined reference to `Json::Reader::parse(std::string const&, Json::Value&, bool)'
undefined reference to `Json::Reader::Reader()'
undefined reference to `Json::Value::~Value()'
undefined reference to `Json::Value::Value(Json::ValueType)'

我对 C++ 有点陌生,include 语句中是否遗漏了什么?或者 jsonCpp 是否需要额外的东西?

感谢您的宝贵时间!

最佳答案

您的代码正在编译,但未链接。您忘记向链接器提供 JSON 共享库文件(或者,在较新的版本中,将合并的 jsoncpp.cpp 添加到您的项目)。

在不了解您的开发环境的情况下,很难给您更具体的说明。

顺便说一句,您正在编写 C++;请使用像 cstdio 这样的 C++ 头文件,而不是 stdio.h。您也未能包含 C++ string 并且幸运的是它通过一些包含它的 JSON header “工作”了。

关于c++ - 包含 jsonCpp header 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5174019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com