5

How do I resolve the following linker error w.r.t jsoncpp operator=.

I create a Json::Value object like this

Json::Value pt;
pt["type"] = 5;
pt["uuid"] = "f8c74622-d45e-4cfa-fe00-5e7042431c72";
pt["start frame"] = 10;
pt["duration"] = 20;
pt["payload"] = "aedddefffsadf";

This gives the following linker error when I try to link against the default libjsoncpp-dev shipped with Ubuntu 14.04

undefined reference to `Json::Value::operator=(Json::Value)'

extra info:

And I don't get this linker error when compiled and linked against the latest jsoncpp from GitHub.

value.h (installed by ubuntu apt) in /usr/include/jsoncpp/json has

Value &operator=( const Value &other );

and the latest jsoncpp value.h has

Value &operator=(Value other);
2
  • You'd better add tags c++ and c++-11 Commented Feb 11, 2015 at 3:05
  • 1
    Generally you need to compile with the same version of the header files as the version of the library you (eventually) want to link with. If you compile with one version of the headers and link with a different version of the library, bad things tend to happen. If you want to be able to link with default libjsoncpp-dev from Ubuntu 14.04, be sure to use those header files. Commented Feb 12, 2015 at 0:51

1 Answer 1

2

Debian ships with jsoncpp-0.6.0-rc2. I'll bet Ubuntu does too.

Simply switch to jsoncpp-0.8.z, which are binary-compatible with 0.6.0-rc2 and include most enhancements and bug-fixes from 1.y.z.

Actually Debian is switching to 0.8.z presently. Until Ubuntu updates their shipped version, you might have to avoid new features (mainly the Builders) and instead use the deprecated Readers/Writers, which is probably what you do already. So it should be easy for you to get everything working.

Sign up to request clarification or add additional context in comments.

4 Comments

Are you saying that this is a bug in 0.6.0-rc2?
No, not a bug. A non-binary-compatible change was made in 1.y.z (and 0.7.z, accidentally). But 0.8.z is binary-compatible with 0.6.0-rc2. The change was for the copy-and-swap idiom, for efficiency, not actually necessary.
So how has the OP found himself with a linker error from only "the default libjsoncpp-dev shipped with Ubuntu 14.04"?
Somehow, OP has compiled against a recent version of the header, while linking against the old library. I don't know how.

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.