无法在LInux上使用Eclipse编译简单的jsoncpp程序

时间:2011-05-24 20:41:54

标签: c++ eclipse jsoncpp

文件位于/ home / shivang / Desktop位置,文件名为sh1.cpp 该文件的源代码如下所示

#include iostream
#include json/json.h
#include json/reader.h

using namespace std;
using namespace Json;

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

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

    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

显示以下错误消息。

/home/shivang/Desktop/sh1.cpp: In function ‘int main()’:
/home/shivang/Desktop/sh1.cpp:10:2: error: ‘Value’ was not declared in this scope
/home/shivang/Desktop/sh1.cpp:10:8: error: expected ‘;’ before ‘value’
/home/shivang/Desktop/sh1.cpp:11:2: error: ‘Reader’ was not declared in this scope
/home/shivang/Desktop/sh1.cpp:11:9: error: expected ‘;’ before ‘reader’
/home/shivang/Desktop/sh1.cpp:13:16: error: ‘reader’ was not declared in this scope
/home/shivang/Desktop/sh1.cpp:13:38: error: ‘value’ was not declared in this scope

配置gcc 4.5.2版(Ubuntu / Linaro 4.5.2-8ubuntu4)               jsoncpp-SRC-0.5.0               eclipse-cpp-helios-SR2-linux-gtk

1 个答案:

答案 0 :(得分:0)

我之前从未使用过Json或C ++。但有一点谷歌搜索引导我this page。我认为在您的包含列表中添加以下行应该会有所帮助:

#include <json/value.h>