1
votes

I'm very new to xcode and c++ programming so please let me know if I'm going about this all wrong. Basically, I want to create a C++ project that requires a library to deal with making and receiving json calls. (this will eventually be integrating as the 'engine' of an iOs and android app.) I want to use xcode to create this and I tried installing libjson but couldn't get it to recognize. I then tried using JsonCpp and followed the instruction.

1) I downloaded the tar.gz 2) I downloaded the scons python program and in the jsoncpp folder and ran the appropriate command (something like 'python scons.py platform=linux-gcc check')

This created a .a and a .dylib file

Next, i tried to move the files into the project and link it in xcode from 'Link Binary With Libraries' portion of the Build Phases tab in the project settings.

I linked up the code to my file with an include statement: #include "lib/jsoncpp/json.h"

This led to the following error:

Undefined symbols for architecture x86_64: "Json::Reader::parse(std::__1::basic_string, std::__1::allocator > const&, Json::Value&, bool)", referenced from: jsonParser::parseLogin(std::__1::basic_string, std::__1::allocator >&, std::__1::basic_string, std::__1::allocator >&) in jsonParser.o ld: symbol(s) not found for architecture x86_64

(null): "Json::Reader::parse(std::__1::basic_string, std::__1::allocator > const&, Json::Value&, bool)", referenced from:

All I am trying to do is set up this library but It has been keeping me from working on my code for the past day looking for a solution.

For the libjson library, I tried following the directions here but with similar issues: Cannot Install libjson in c++ Embedding in XCode 4 Project

Does anyone have any advice on steps I can take to set this up? Thank you for your time.

2
A fairly complete JSON encode/decode package is only 2K lines or so. Not worth the trouble of doing the whole separate compilation thing (especially if you don't understand it) -- just include the source in your project.Hot Licks
I tried your suggestion. jsoncpp in particular has an amalgamate.py script which let me make a simple header and source file. However, when I tried to implement that the source got all these errors related to debug codes. I've been trying it for a few days and couldn't figure it out but in the end we ended up finding a visual studio project with all of that set up. Since I don't have too much time at the momemnt, I'm going to defer to using this and try to take a whack at this issue again later (I'll have to when I try migrating the code to xcode)... Thanks for your help @Hot LicksThinkBonobo

2 Answers

2
votes

In the project navigator (left side of XCode), click above your project. Then:

Build Phases -> Link binary with libraries

Here is where you add all libraries and/or frameworks that will be linked to your application. Leave this page open, then drag and drop the libraries inside the libraries area... that's it! no secret!

If it doesn't work. You are probably with a wrong library. Try lipo -info library to check if the library architeture is the same you are trying to use (x86_64 in this case).

If it still doesn't work. You are probably with C++ incompatibility. Any mixing of libstdc++ and libc++ in builds will cause trouble. All C++11 code built with clang should set an environment variable: CXX=clang++ -std=c++11 -stdlib=libc++, or add CXX="clang++ -std=c++11 -stdlib=libc++" as an argument to configure.). If you compiled libjson via command line, check it again. But, for libJSON, it's much easier if you open a new XCode Project and add the files to the project instead of compile it via command line.

2
votes

In the end, I tried just copying the entire source project into my xcode project and building it. it ended up solving the issue.

This is How I solved the issue:

  1. download libjson from sourceforge
  2. unzip it.
      -
  3. move the _internal folder, libjson.h, and JSONOptions.h into the xcode project folder
  4. add those files to your xcode project
  5. remove the test suite files from this project as you don't need them
  6. build your main to test it and you should be good to go.