Cannot Install libjson in c++ Embedding in XCode 4 Project

本小妞迷上赌 提交于 2019-12-12 00:27:57

问题


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:

  • Using libjson in a C++ project
  • http://sourceforge.net/p/libjson/discussion/1119662/thread/2e0774a7

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



来源:https://stackoverflow.com/questions/17495357/cannot-install-libjson-in-c-embedding-in-xcode-4-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!