• 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: Xcode, Dyld, External Dynamic Libraries and Setting {DY}LD_LIBRARY_PATH for Running Targets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Xcode, Dyld, External Dynamic Libraries and Setting {DY}LD_LIBRARY_PATH for Running Targets


  • Subject: Re: Xcode, Dyld, External Dynamic Libraries and Setting {DY}LD_LIBRARY_PATH for Running Targets
  • From: Ken Thomases <email@hidden>
  • Date: Sat, 25 Jul 2009 00:20:03 -0500

On Jul 24, 2009, at 4:54 PM, Grant Erickson wrote:

I've added libboost_system.dylib and libboost_filesystem.dylib to my project
as "Relative to Build Products" and added them as link libraries to my
target. This all works well and fine.


However, when I go to run the target in the debugger, I get:

   [Session started at 2009-07-24 14:37:54 -0700.]
   dyld: Library not loaded: libboost_filesystem.dylib
     Referenced from:
${HOME}/Source/results/Debug/MyApp.app/Contents/MacOS/MyApp
     Reason: image not found

[...]

Long-term, my intent is to set rpath when building Boost such that otool -D
reports:


/Library/Application Support/Nuovations/lib/ libboost_filesystem.dylib
/Library/Application Support/Nuovations/lib/libboost_system.dylib


because setting LD_RUNPATH_SEARCH_PATHS for the application (e.g. MyApp)
only seems to be supported for 10.5 and I am deploying against 10.4.


However, even in that case, I need to tell Xcode "Hey, the libraries you are
looking for when running the binary are <here>, not in their installed
locations (e.g. /Library/Application Support/Nuovations/lib) just like the
five frameworks you resolved."

Typically, you would not install libraries into any place like / Library/Application Support/Nuovations/lib. Stuff in Application Support should not be critical to the functioning of your app.


<http://developer.apple.com/documentation/MacOSX/Conceptual/BPFileSystem/Articles/LibraryDirectory.html >

Rather, the libraries necessary for your app to run should be inside the app bundle. Usually, in MyApp.app/Contents/Frameworks.

<http://developer.apple.com/documentation/CoreFOundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW19 >

To put them there, create a Copy Files build phase for the application target in your Xcode project. Add the libraries to that build phase.

<http://developer.apple.com/documentation/developertools/Conceptual/XcodeBuildSystem/200-Build_Phases/bs_build_phases.html#//apple_ref/doc/uid/TP40002690-CJAHHAJI >

The next thing you have to do is adjust the references to those dependent libraries within your main executable. For this, you create a Run Script build phase which invokes the install_name_tool command, with the -change option. Also, you should use the @executable_path placeholder in the new path to make it relative to your app's main executable. For example:

install_name_tool -change libboost_filesystem.dylib @executable_path/../Frameworks/libboost_filesystem.dylib "$TARGET_BUILD_DIR/$EXECUTABLE_PATH"

(In case email wraps it, the above is all one line.)

This Run Script build phase should have $(TARGET_BUILD_DIR)/$ (EXECUTABLE_PATH) as its input file, to let Xcode know it depends on the executable having been built before it runs.

That should do it.

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


  • Follow-Ups:
    • Re: Xcode, Dyld, External Dynamic Libraries and Setting {DY}LD_LIBRARY_PATH for Running Targets
      • From: Grant Erickson <email@hidden>
References: 
 >Xcode, Dyld, External Dynamic Libraries and Setting {DY}LD_LIBRARY_PATH for Running Targets (From: Grant Erickson <email@hidden>)

  • Prev by Date: Re: Xcode, Dyld, External Dynamic Libraries and Setting {DY}LD_LIBRARY_PATH for Running Targets
  • Next by Date: Re: Xcode, Dyld, External Dynamic Libraries and Setting {DY}LD_LIBRARY_PATH for Running Targets
  • Previous by thread: Re: Xcode, Dyld, External Dynamic Libraries and Setting {DY}LD_LIBRARY_PATH for Running Targets
  • Next by thread: Re: Xcode, Dyld, External Dynamic Libraries and Setting {DY}LD_LIBRARY_PATH for Running Targets
  • Index(es):
    • Date
    • Thread