tags:

views:

71

answers:

2

Hi,

I just started programming in Xcode and I'm trying to write an iphone application. I started out with a simple template for Iphone development and took it from there. Now I would like to build a command line tool (for converting data) which reuses some of the classes in my iphone project. I managed to add a new target 'convert', link the appropriate source code to the target, make the target dependent on the main target. Everything builds, so far so good, but it does not generate the right executable, it will build only build/Debug-iphonesimulator/convert which is not runnable from the command line (I'm guessing because it is not linked with the right libraries).

~/Documents/XCode/SQLiteTutorial> ./build/Debug-iphonesimulator/convert
dyld: Symbol not found: _OBJC_CLASS_$_NSCharacterSet
  Referenced from: /Users/marc/Documents/XCode/SQLiteTutorial/./build/Debug-iphonesimulator/convert
  Expected in: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
 in /Users/marc/Documents/XCode/SQLiteTutorial/./build/Debug-iphonesimulator/convert
Trace/BPT trap

Is this possible with xcode at all? I'm not sure what kind of extra information you would need to answer this question, so let me know what to provide, if anything.

Kind regards, Marc van Kempen.

A: 

iPhone SDK does not officially support building command-line tools. iPhone does not run command-line tools; at least, not without jailbreaking.

Franci Penov
Ah sorry, it is not meant to be run on the iphone but on my development machine. It is a tool to convert data to be included with the iphone app.So what I want is to build an iPhone app and a Mac OS X command line application in the same project, or any other configuration that will allow me to be able to reuse the classes from the iPhone app that represent the data.
Marc van Kempen
Makes sense. Please update your question and ignore my answer :-).
Franci Penov
+1  A: 

What if you simply created a different project entirely and then dragged in the relevant classes you wanted to reuse, but instead of copying them, merely used references to them? Just don't select 'copy items into destination's folder' option when you drag the class files into your groups & files pane. That way your CL project always uses the latest version from the main iPhone one.

Having it all in one project would no doubt be cleaner though.

Joost Schuur
Thanks, I tried this solution and it works. As you say it is not the most ideal scenario but it'll do for now. Still curious how other people solve this, on bigger projects this must be an issue.
Marc van Kempen
This is what I do for my Mac / iPhone cross-platform projects, because I haven't come across an easy way to build different targets for the two platforms within one project. I recommend watching the WWDC 2010 videos about Xcode 4, because (without breaking NDA by discussing too much) it makes this easier to manage.
Brad Larson
I did the same but it doesn't work. I just need to use one class file to do the task to be link in my command file, so I only need to reference that class file but when I build the project it has a lot of errors since the class file I referenced uses a lot of underlying core classes of the main iphone project, do I have to make a reference for all the files in the main iphone project?
ivanceras