包括jsonCpp头的问题 [英] Problems including jsonCpp headers

查看:2154
本文介绍了包括jsonCpp头的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的C ++代码中实现jsoncpp库,我写了一段简单的代码试试,甚至不编译。

I'm trying to implement the jsoncpp libraries in my C++ code, I wrote a simple piece of code just to try it out, and it's not even compiling.

#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需要额外的东西?

I'm a bit new to C++, is there something I'm missing in the include statement? Or does jsonCpp need something extra?

谢谢您的时间。

推荐答案

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

Your code is compiling, but it is not linking. You forgot to provide the JSON shared library files to your linker (or, on newer versions, to add the amalgamated jsoncpp.cpp to your project).

你的开发环境,很难给你更具体的说明。

Without knowing more about your development environment, it's hard to give you more specific instructions.

BTW,你正在写C ++;请使用 cstdio ,而不是 stdio.h 的C ++标题。你也不能包括C ++ string ,并且很幸运,它通过一些JSON头包括它为你工作。

BTW, you're writing C++; use C++ headers like cstdio, not stdio.h, please. You also failed to include C++ string and got lucky that it "worked" through some JSON header including it for you.

这篇关于包括jsonCpp头的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆