问题包括jsonCpp标头

Jay*_* Le 3 c++ compiler-errors header include jsoncpp

我正在尝试在我的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;
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

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)'
Run Code Online (Sandbox Code Playgroud)

我对C++有点新意,在include语句中有什么我想念的吗?或者jsonCpp需要额外的东西吗?

感谢您的时间!

Lig*_*ica 5

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

如果不了解您的开发环境,很难给出更具体的说明.

顺便说一下,你在写C++; 请使用C++标题cstdio,不是stdio.h.您也未能包含C++,string并且很幸运它通过一些JSON标题"工作",包括它.