• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Linking libraries
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Linking libraries


  • Subject: Re: Linking libraries
  • From: Ken Thomases <email@hidden>
  • Date: Fri, 19 Jun 2009 22:26:32 -0500

On Jun 19, 2009, at 9:58 PM, Matthew Unrath wrote:

I'm new to Xcode and programming in general.

I am using a library that has a .dylib file. I have added it to my project, and it builds and runs fine. However, when I try to run the application it generates, it brings up an error:

Dyld Error Message:
Library not loaded: /usr/local/lib/libirrklang.dylib
Referenced from: /Users/Shared/Empty_Xcode2/build/Release/ HelloWorld.app/Contents/MacOS/HelloWorld
Reason: image not found


I can modify the directory Xcode searches for the .dylib for a Carbon Shell Tool by running a script:

install_name_tool -change /usr/local/lib/libirrklang.dylib @executable_path/libirrklang.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME"

This makes it look in the directory the Shell Tool is located rather than /usr/local/lib.

It seems that this approach doesn't work for an Application target (the script doesn't work on application files). Is there another way to change the directory in a similar way?

The string "$TARGET_BUILD_DIR/$PRODUCT_NAME" in the above command will resolve to something like "/Users/Shared/Empty_Xcode2/build/Release/ HelloWorld" in your example. That is, $PRODUCT_NAME is "HelloWorld". It's not "HelloWorld.app" nor even "HelloWorld.app/Contents/MacOS/ HelloWorld".


The install_name_tool will work fine if you direct it to the actual executable in the application bundle. You can use "$TARGET_BUILD_DIR/ $EXECUTABLE_PATH". That should still work for a shell tool -- $EXECUTABLE_PATH should always be the path to the executable, no matter the type of product being built.

Now, you may not want to change the library reference to "@executable_path/libirrklang.dylib". The dynamic library should probably go someplace else within the application bundle rather than right next to the executable in the Content/MacOS directory. Apple recommends putting them into the Contents/Frameworks directory within the bundle:

<http://developer.apple.com/documentation/CoreFOundation/Conceptual/CFBundles/Concepts/BundleAnatomy.html#//apple_ref/doc/uid/20001119-107871-TPXREF6 >

So, you could change the library reference within your executable to "@executable_path/../Frameworks/libirrklang.dylib".

Cheers,
Ken

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Linking libraries (From: Matthew Unrath <email@hidden>)

  • Prev by Date: Linking libraries
  • Next by Date: error: 'AuthorizationRef' has not been declared Help!
  • Previous by thread: Linking libraries
  • Next by thread: error: 'AuthorizationRef' has not been declared Help!
  • Index(es):
    • Date
    • Thread