Search code examples
objective-cmacoscocoadylibdynamic-library

How to link a dynamic library Xcode 5


Can you point me to a tutorial which shows how to link to a dynamic library. I created a dynamic library. Now I've got no clue how to include it into your project.

What I tried is 1.I copied the dylib and header folder into my project. 2. I gave library search path as $(PROJECT_DIR) 3. I gave header search path as $(PROJECT_DIR)/include. Now it builds and links just fine. But when I run it, it gives me this error

.yld: Library not loaded: /usr/local/lib/test_dynamic_lib.dylib

Now i read in documentation that you have to install the library in that path. How to do that? or you can manipulate runpaths. I didnt get a clue what it says. I'm actually a beginner in cocoa development.

Can you explain how to do that? Or point to a tutorial. I couldn't find any.


Solution

  • I found the answer. I wrote a build script on my target.

    export DYLIB=myLibrary.dylib mkdir "$TARGET_BUILD_DIR/$TARGET_NAME.bundle/Contents/Frameworks" cp -f "$SRCROOT/$DYLIB "$TARGET_BUILD_DIR/$TARGET_NAME.bundle/Contents/Frameworks" install_name_tool -change @executable_path/$DYLIB @loader_path/../Frameworks/$DYLIB"$TARGET_BUILD_DIR/$TARGET_NAME.bundle/Contents/MacOS/$PRODUCT_NAM

    And yes thnx The Paramagnetic Croissant for poiting me in the right direction.