Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a simple library to an xcode 4 project

Tags:

xcode

ios4

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.

like image 1000
user813611 Avatar asked Aug 07 '11 21:08

user813611


People also ask

How do I add an external library to Xcode?

Right click on your project in the left hand column (file listing), click “Add existing files”, then go to the prebuilt library (for me it was in /usr/local/lib), and add the file. You don't have to copy it into the directory, you can just add it and it should work.

What is a static library in xcode?

Static library - a unit of code linked at compile time, which does not change. However, iOS static libraries are not allowed to contain images/assets (only code). You can get around this challenge by using a media bundle though.

What is static library iOS?

A static library is a collection of compiled object files combined into a single library file, that may be linked into an app or framework target just like single object files are linked.

How do I create an Objective C project in Xcode?

To create a new Objective-C project select Create a New Xcode Project from the Welcome Screen. As an alternative you can select File > New > New Project… from the menu at the top of your screen. In the Mac OS X section left-hand pane select Application.


1 Answers

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.

like image 159
memmons Avatar answered Oct 26 '22 23:10

memmons