3

I'm trying to create a Json message using Jsoncpp. I've done as follows:

#include <string>
#include <iostream>
#include <sstream>    
#include <json/json.h>

int main()
{
  std::string Value = "5.17e9";
  std::string Type = "TX";
  std::string Parameter = "Frequency";

  Json::Value root; 
  root.append("Type");
  root.append("Parameter");
  root.append("Value");
  root["Type"] = Type;
  root["Parameter"] = Parameter;
  root["Value"] = Value; 

  Json::FastWriter fastwriter;
  std::string message = fastwriter.write(root);
  std::cout<<message<<std::endl;

  return 0;
 }

compiling this code using the following command line:

g++ -o clients clients.cpp -ljsoncpp -lzmq

This Kind of error occurs:

clients.cpp:(.text._ZN20multi_usrp_emulation7client1Ev[_ZN20multi_usrp_emulation7client1Ev    ]+0x1d9): undefined reference to `Json::Value::operator=(Json::Value)'
clients.cpp:(.text._ZN20multi_usrp_emulation7client1Ev[_ZN20multi_usrp_emulation7client1Ev    ]+0x224): undefined reference to `Json::Value::operator=(Json::Value)'
clients.cpp:(.text._ZN20multi_usrp_emulation7client1Ev[_ZN20multi_usrp_emulation7client1Ev    ]+0x26c): undefined reference to `Json::Value::operator=(Json::Value)'
collect2: error: ld returned 1 exit status

What is wrong with my code?

2
  • What version of jsoncpp are you using? Perhaps it is related to this issue: github.com/open-source-parsers/jsoncpp/issues/484 ? Commented Jun 13, 2016 at 13:47
  • I don't how to check the version. But I've downloaded today via github. I read the question that you attached but I didn't understand it well..can you help me? Commented Jun 13, 2016 at 14:10

1 Answer 1

4

I'm not sure about the link error, but there is a problem with the code that might be handled differently in your compiler. It's a runtime error for me.

Json::Value root; 
root.append("Type"); // makes root into arrayValue
root["Type"] = Type; // accesses root as an objectValue
// triggers assert in Json::Value::resolveReference

this is how I do it:

Json::Value root; 
root["Type"] = Type;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.