0

I simply cannot figure out how to get libjson installed as part of my c++ project. I've been through everything online. Am embedding this in my project.

First I tried this

  1. Moved the libjson directory into my project
  2. Commented out: #define JSON_LIBRARY
  3. Ran make
  4. Added #include "libjson/libjson.h"

Project builds ok..

Added the following to my main.cpp file:

JSONNode n = libjson::parse(json);

Build fails with two errors:

Undefined symbols for architecture x86_64:
  "JSONWorker::parse(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      libjson::parse(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in main.o
  "internalJSONNode::deleteInternal(internalJSONNode*)", referenced from:
      JSONNode::decRef()     in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

I've also tried make && sudo make install and compiling the project manually. Same errors:

g++ main.cpp -o junk -I/usr/include/libjson -ljson

I have also tried:

SHARED=1 make && sudo SHARED=1 prefix=/usr/local make install

Finally, I've tried copying the libjson file into my project and also get the same errors.

Please can someone show me what I'm doing wrong? We were using rapidjson but prefer the look of libjson. The major problem is that we cannot install it!

Other references used:

3
  • Adding the header file ain't no enuf. Commented Jul 5, 2013 at 19:02
  • Is your libjson built for x86_64? Commented Jul 5, 2013 at 19:19
  • @n.m.No idea, I built in on my mac but it's to be compiled on a different machine later on. Commented Jul 5, 2013 at 19:49

1 Answer 1

1

I'm answering my own question because this was a pain in the neck. Here's what I did to get it working.

  1. Comment out #define JSON_LIBRARY in JSONOptions.h
  2. Run make
  3. Add libjson.a to your project
  4. Add libjson.h to your project
  5. Add JSONOptions.h to your project
  6. Add #include "libjson.h" to your main project file

Voila. Hope you don't waste as much time as I did on this...

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.