1

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.

Adwait
  • 290
  • 2
  • 11
  • 2
    `sudo cp $PROJECT_DIR/test_dynamic_lib.dylib /usr/local/lib/` – The Paramagnetic Croissant Oct 14 '14 at 14:33
  • um this is stupid,but can we do that through xcode? if I'm to deliver my app on the app store, how would I manage this. As I said, i'm really new to this. – Adwait Oct 14 '14 at 14:37
  • stupid? Since when is copying a file considered stupid? If you want to put your app on the AppStore, you will still need some mechanism to have the dynamic library installed on your user's system anyway. (or if you don't want that, use a statically linked library instead.) – The Paramagnetic Croissant Oct 14 '14 at 14:43
  • I meant my question is stupid. :) How can I get that library installed on the users system? Actually if you can point me to a tutorial that would be very helpful – Adwait Oct 14 '14 at 14:45

1 Answers1

1

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.

Adwait
  • 290
  • 2
  • 11