views:

160

answers:

2

For a while now I have been killing spare time by creating a 2D game programming toolkit/library. It is written in Objective C, and consists of an OpenGL rendering system and a whole bunch of AI, physics code, a bunch of specialized containers and other game related stuff. Apart from the OpenGL based View mechanism (obviously), most of this code should be easily portable to iOS since it only uses the Foundation Framework and that framework appears to be implemented on iOS. So far I have only been testing the various components using a Cocoa NSOpenGLView but now I want to create a OS X/iOS library.

My Question is:

What's the best strategy for creating an Objective-C library that can be integrated into either iOS or OS X applications?

The Xcode 'New Project' dialog offers only:

iPhone OS; Library:
- Cocoa Touch Static Library.

Mac OS X, Framework and Library:
- Cocoa Framework
- Cocoa Library
- Bundle
- BSD C Library
- STL C++ Library
- JNI Library

At first glance none of these seems to be intended for creating a library that can be integrated into either OS X or iOS applications.

A: 

You can't. iOS isn't Darwin, no matter how hard you want it to be. It's actually a stripped down version of Max OS Jaguar (10.3). However, binaries on Mac won't run on iOS, because a Mac is powerpc-apple-darwin or i?86-apple-darwin. An iphone is arm-apple-darwin, so it uses an almost completely different CPU Architecture, even if the OS looks the same. The source code for your library is almost definitely transferable, but no binary, object, or dylib file will transfer. Sucks =(

Leo Izen
I wasn't thinking about binary libraries. I was kind of hoping I could have one "Game Library" project that could be included, via Xcode, in either an iPhone app or an OS X app. I Just did this with a cryptographic library written in C. It can be included and compiles by code running on an embedded system as well as a full blown Linux server. What you seem to be saying is that I have to maintain two Objective-C source trees, one for OS X and one for iOS that contain 90% the same code.
os x nerd
Pretty much. =(
Leo Izen
+1  A: 

Well, I finally found the correct set of Google search terms, so to answer my own question (DOH!), it seems to be possible to share code, at least between iPhone apps and possibly also iPhone and OS X apps within certain limits. You have to create a 'static library' and use 'cross-project references':

www.clintharris.net/2009/iphone-app-shared-libraries/
amateurinmotion.com/articles/2009/02/08/creating-a-static-library-for-iphone.html
zetetic.net/blog/2010/02/15/building-static-libraries-to-share-code-on-iphone-and-mac-os-x-projects/
weston-fl.com/blog/?p=808

Haven't tested any of this yet but it looks promising.

os x nerd