【发布时间】:2011-03-02 21:55:17
【问题描述】:
我正在尝试在我的 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 需要额外的东西?
感谢您的宝贵时间!
【问题讨论】:
-
包括
(您正在使用)而不是 stdio.h (您不是)以及 正如 Tomalak 指出的那样。此外,您几乎绝对不需要 #ifndef json_included 东西,因为它应该在您正在使用的标题中。
标签: c++ header include jsoncpp compiler-errors