views:

41

answers:

1

As I'm sure you're aware it's common to include both debug and release builds of libraries in their SDKs. My question is whether there exists a standard way of going about this for a Mac OS X framework in terms of distribution and possibly Xcode integration?

One option is to ship a second entirely separate framework, e.g. MyLibrary.framework and MyLibraryDebug.framework. If this is the correct way to go about it, is there some trick to telling Xcode to use the right one? When adding a framework to an Xcode project it didn't seem to have the option of only adding it to a single build configuration, and it seems kludgy to have to resort to putting the correct -framework MyLibrary[Debug] command line option in manually for the respective configurations!

Thanks.

+1  A: 

The Mac OS X dynamic linker (dyld) has a feature for exactly this purpose: DYLD_IMAGE_SUFFIX. It'll allow you to dynamically load the debug version of any framework or shared library you've linked to. Then you don't need an entirely separate .framework bundle; simply create another shared library named MyLibrary_debug. For example, CoreFoundation in Tiger includes debugging and profiling variants (which look like they haven't received security updates, but anyway):

% ls -l /System/Library/Frameworks/CoreFoundation.framework/Versions/A/
total 20080
-rwxr-xr-x    1 root  wheel       1M Sep 10 17:55 CoreFoundation*
-rwxr-xr-x    1 root  wheel       6M Apr 24  2007 CoreFoundation_debug*
-rwxr-xr-x    1 root  wheel       2M Apr 24  2007 CoreFoundation_profile*

With Apple's frameworks as above, the standard "debug" suffix is _debug. (The "Use [debug] suffix when loading frameworks" setting in the General pane on an executable within Xcode sets DYLD_IMAGE_SUFFIX=_debug).

You might think using _debug as well is a good idea, but I suggest you don't, because Apple has broken the _debug versions of their frameworks on several occasions (some examples). As of Leopard only libSystem, libmx and libmathCommon come with debug variants, but in Snow Leopard they broke again (I ran into this problem myself).

If you pick a different suffix for your debug library, you should not trigger Apple's bugs and still be able to share the rest of your framework (headers, resources, etc.) between the normal and debug variants.

Nicholas Riley