سؤال

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:

هل كانت مفيدة؟

المحلول

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...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top