问题
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
- Moved the libjson directory into my project
- Commented out: #define JSON_LIBRARY
- Ran make
- 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.
- Comment out #define JSON_LIBRARY in JSONOptions.h
- Run make
- Add libjson.a to your project
- Add libjson.h to your project
- Add JSONOptions.h to your project
- 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