我想在我的C++代碼中實現jsoncpp庫,我寫了一段簡單的代碼來試用它,它甚至不編譯。包括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++,有什麼我失蹤的包含語句?或者jsonCpp需要額外的東西?
謝謝你的時間!
包括(您正在使用的)不是stdio.h(您不是),以及Tomalamala指出的。此外,你幾乎肯定不需要#ifndef json_included的東西,因爲它應該在你正在討論的頭文件中。 –
2011-03-02 22:06:34