0

The File is at the location /home/shivang/Desktop and the filename is sh1.cpp Source code for the file is given below

#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;
}

The following error messages are displayed.

/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

Configuration gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) jsoncpp-src-0.5.0 eclipse-cpp-helios-SR2-linux-gtk

admdrew
  • 3,790
  • 4
  • 27
  • 39
  • Some Googling has shown dat dis maybe a linker problem and I have to add a shared library while compiling. /workspace/hello/src$ g++ hello.cpp -l libjson_linux-gcc-4.5.2_libmt.so -L /usr/lib/ /usr/bin/ld: cannot find -llibjson_linux-gcc-4.5.2_libmt.so But the file is located in the specified folder.Is this a permissions issue? – shivang seth May 26 '11 at 05:59

1 Answers1

0

I have never used Json or C++ before. But a little googling around led me to this page. I think adding the following line to your list of includes should help:

#include <json/value.h>
Apoorv
  • 1,091
  • 6
  • 19
  • I implemented what you said but I am still getting the same errors. You sure this not a linker problem. – shivang seth May 26 '11 at 05:02
  • Some Googling has shown dat dis maybe a linker problem and I have to add a shared library while compiling. /workspace/hello/src$ g++ hello.cpp -l libjson_linux-gcc-4.5.2_libmt.so -L /usr/lib/ /usr/bin/ld: cannot find -llibjson_linux-gcc-4.5.2_libmt.so But the file is located in the specified folder.Is this a permissions issue? – shivang seth May 26 '11 at 05:57
  • Obviously one cannot tell that from here. I had assumed your project setup was fine. Can you read that "so" file? What happens when you do an `ls -l` on that file? The link I mentioned also has a step by step tutorial on how to get started. Can you make sure you followed all the steps? – Apoorv May 26 '11 at 07:42