6

I know this is a very simple question but I have been struggling with it for a while. I have read a few threads but still can seem to find the answer.

I am trying to add this DDMathParser library to my existing project. The math parser documentation states

"Simply copy the "DDMathParser" subfolder into your project, #import "DDMathParser.h", and you're good to go."

I added the subfolder to my project and added the header `#import "DDMathParser.h' to my first view controller. At first Xcode was stating that it can't find the file. I took the advice from another thread and changed my header to include the folder

#import "DDMathParser/DDMathParser.h"

Xcode seems to find the folder and header file but when I run a test from the documentation such as

NSLog(@"%@", [@"1 + 2" numberByEvaluatingString]);

I am getting the error 'Thread 1: Program received sginal: "SIGABRT"' I can see in the DDMathParser sample file that there is a target, I am wondering if this is my problem.

To clarify the question I am trying to add the DDMathParser library to a simple view controller and run the staement NSLog(@"%@", [@"1 + 2" numberByEvaluatingString]); Any help/clarification in doing so would be greatly appreciated.

user813611
  • 209
  • 4
  • 13

2 Answers2

12

First, please do not add the DDMathParser code to your project via a subfolder copy. Doing so will make it a pain to easily grab any future updates to the code and in general is not a very good approach to including external code in your projects.

Instead, you should add the git repo as a submodule of your project (you are using git, right?) and import the relevant files to your project. Here's a step-by-step solution:

  1. Add the DDMathParser repo as a submodule to your project. Here are instructions on how to add a submodule in your project directory. Take a look at that answer, but for brevity's sake, you'll issue this command from terminal in your project's root directory: git submodule add https://github.com/davedelong/DDMathParser.git External/DDMathParser. This will create a new subdirectory named External to your project root directory and inside External the DDMathParser project will be copied.
  2. Add the DDMathParser directory to your project. It will be found in <Your Root Project Dir>/External/DDMathParser/DDMathParser directory. Be sure to check the "add to targets" checkbox and not to check the "copy items" checkbox.
  3. Add #import "DDMathParser.h" to your viewcontroller.

DDMathParser should now work as you expect. If the author comes out with an update to the code you can just issue the following command from terminal to pull the latest updates from github: git submodule update.

Note: I created a new project from scratch, followed these steps and included your NSLog() example to ensure that there aren't any issues.

Community
  • 1
  • 1
memmons
  • 40,222
  • 21
  • 149
  • 183
  • Thanks for the reply your post was very helpful however I am still getting errors. I followed your instructions step by step and was able to download the code into the External directory, add the files to the project and add the header without problems but when I run my test program I get 15 errors all stemming from DDMathEvaluator.m and _DDDEcimalFunctions.m. I cant seem to figure out what I did differently from you. Please let me know if you have any suggestions and thank you very much for the help! – user813611 Aug 08 '11 at 02:51
  • Hmm...are you sure you selected your target when y ou were adding the DDMathParser directory to your project? If you select DDMathEvaluator.m can you confirm that it is included in your target? As I said, I was walking through this step-by-step as I was typing up the help and it worked fine. As a test, could you create a new project from scratch and give it a try? – memmons Aug 08 '11 at 03:29
  • Thanks again for the reply Harkonian, 1. I created a new project named mathParserTest view based app with git repository 2. I used the terminal command to download the DDMathParser in the projects root folder 3. I choose FILE->Add files to "mathParserTest" then I select the Dir>/External/DDMathParser/DDMathParser with Copy items into groups unchecked, Create groups for any added folders checked and Add to targets mathParserTest checked. The target has the IB icon with the name mathParserTest next to it. The folder with files imports into the project and looks fine until i compile. – user813611 Aug 08 '11 at 06:17
  • If you have a quick second to look at my test project you can download it here: http://www.box.net/shared/6vjursbccl26vucj8sfp – user813611 Aug 08 '11 at 06:38
  • Give me an hour or so and I'll grab it and look. – memmons Aug 08 '11 at 14:03
  • 2
    In your build settings, change your compiler to use Apple LLVM 2.1 instead of LLVM GCC 4.2. I have no idea why GCC has an issue with it -- but in general use the Apple stack if you can. After changing to LLVM 2.1 it compiled fine, your "will this compile" log displayed correct as well as a test log I added using the DDMathParser. – memmons Aug 08 '11 at 15:40
  • It works! Interesting info about the compiler, I will try to stick with Apple LLVM 2.1 from here on out. Thank you so much for your time. – user813611 Aug 08 '11 at 16:50
0

I followed these steps too, until I could make it work. The suggested method has some flaws.

  1. As the guy before me had it --- You only bring in the SOURCES of DDMathParser, and compile them as part of your target. This binds you to use the same build-settings, SDK version and deployment system-version as the author of DDMathParser. Examples:

    • didn't use ARC in my target --- now I must.
    • I intended to use MacOS 10.8 SDK in my project (for many good reasons) but I got strange ARC compilation error in one DDMathParser source, that only disappeared as I switched to SDK 10.9 (version used by author in his samples and docs).
    • I MUST provide my application for MacOS 10.8 and above, now I'm unsure it will work
  2. I don't know what happens if I push my parent repo to the server, and another friend pulls it. Will he receive the DDMathParser repo automatically? How? He must have access to it! The scheme does not seem complete to me.

I will suggest to aid the author in packaging his DDMathParser as a framework, and then you will be able to import the PROJECT FILE of DDMAthParser into your project --- not the sources, and simply link against the product of DDMathParser project (a private framework). Seems much nicer. the framework can be compiled using the author's settings, and we just receive the nicely-packaged binary.

Motti Shneor
  • 2,095
  • 1
  • 18
  • 24