tags:

views:

588

answers:

2

I am trying to create an mac application in XCode that has some of its implementation in a dynamic library.

I added a new target (dynamic library) to my XCode cocoa project and after a bit of fighting with frameworks and precompiled headers, have the dynlib compiling - and running successfully from the debugger.

When run standalone however its apparent that the dynlib is in the wrong place. "Library not loaded: /usr/local/lib/testlib.dynlib". On Windows - my more usual platform - Dlls can be placed in the same folder as the exe, and anywhere on the system path.

I would rather like my application to look for its dynlib somewhere in its application bundle (and certain documents seem to confirm this as the correct approach), but I don't know how.

Is it possible to configure the project in XCode so that the dylib actually is copied into the app bundle, in a place where the app will look for it?


It seems I don't need to use otool to reset the search path. If I edit the Target Info -> Build -> Deployment -> Installation Directory I can change, from inside XCode, the path that dyld is going to look at for the dylib. By default for a new dynamic library project, the path was set to /usr/local/lib. Which I have changed to ./ - otool confirms that ./ is now where dyld is going to be looking for this specific dynamic module. Unfortunately ./ doesn't seem to actually refer to any directory in my application bundle :(

So, my questions (not answered in the other thread) now are: 1. How do I enter a meaningful relative path in the Target Info -> ... -> Installation Directory setting, and 2. How can I get XCode to automatically copy the dylib 'target' into the application bundle target's bundle folder at the relative location?

A: 

I believe you are not copying the dynamic library into the application bundle at compile time.

The application is looking for a point in the filesystem, but it only does this after not finding it inside the application bundle. You need to use the otool command to modify the binary after it is compiled (using a build script).

You will find you answer in this previously asked question: How Do I Create a Dynamic Library in Xcode.

Good luck.

Brock Woolf
+2  A: 

At last. Found some official documentation. Its possible to do this entirely within XCode.

I was halfway there modifying the Installed Directory setting of the library: It needed to be: @executable_path/../Frameworks

Then I needed to add a "Copy Files" build step to the library to actually copy it to the Frameworks folder.

Simple. Automatic.

Chris Becke