OF best practice for setting paths to .dylibs?

Hi Everyone,

I may be a bit presumptuous having my first post in Advanced but I am struggling with getting dylibs to load. I am trying to update the addon ofxASR (http://code.google.com/p/ofxasr/) speech recog to work with OF 73/74/XCODE4.

It works fine with OF 62/XCODE3. There are two dylibs that are needed and otool shows:

  
  
libs3decoder.dylib:  
@executable_path/libs3decoder.dylib  
  
libsphinxbase.dylib:  
@executable_path/libsphinxbase.dylib  
  

When running with OF73/XCODE4 the error is:

  
dyld: Library not loaded: @executable_path/libs3decoder.dylib  
  Referenced from: /Users/tom/openFrameworks/of_v0073_osx_release/apps/playgroundApps/ASRwithMoreBrains/bin/ASRwithMoreBrainsDebug.app/Contents/MacOS/ASRwithMoreBrainsDebug  
  Reason: image not found  
  

If I manually add the dylibs to use/lib it works/loads.

I have tried to reconfig the addon using the ofxAddonTemplate as a reference but dylibs are not explained. I am looking at gameoverhack/ofxOpenNI as an example of an addon that uses many dylibs but it uses complex scripts/modules and having to drag the dylibs to the add-on in Xcode. Other examples talk about adding to the target/build phases/run script such as is used for libfmodex.dylib but that seems xcode centric and not that portable.

What is the best way to handle 3rd party dylibs and have a portable addon solution once it is complete?

Thanks

I tried the Run Script route trying to mimic what is done with libfmodex.dylib.

Run Script in target/buildphases

  
cp -f ../../../libs/fmodex/lib/osx/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libfmodex.dylib"; install_name_tool -change ./libfmodex.dylib @executable_path/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME";  
cp -f ../../../addons/ofxASR/libs/sphinx/lib/osx/libs3decoder.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libfmodex.dylib"; install_name_tool -change @executable_path/libs3decoder.dylib @executable_path/libs3decoder.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME";  
cp -f ../../../addons/ofxASR/libs/sphinx/lib/osx/libsphinxbase.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libsphinxbase.dylib"; install_name_tool -change @executable_path/libsphinxbase.dylib @executable_path/libsphinxbase.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME";  

still get error:

  
dyld: Library not loaded: @executable_path/libs3decoder.dylib  
  Referenced from: /Users/tmisage/openFrameworks/of_v0073_osx_release/apps/playgroundApps/ASRwithMoreBrains/bin/ASRwithMoreBrainsDebug.app/Contents/MacOS/ASRwithMoreBrainsDebug  
  Reason: image not found  

the dylibs are in my addons folder

  
.../of_v0073_osx_release/addons/ofxASR/libs/sphinx/lib/osx/libs3decoder.dylib  

What am I doing wrong? Thanks

I haven’t worked extensively with dylibs in Xcode, so I can’t quite grok what’s going wrong here, but my general experience is that @executable_path isn’t always the right answer. This page has a good discussion on the other options, including @loader_path and @rpath: http://www.mikeash.com/pyblog/friday-qa-2009-11-06-linking-and-install-names.html And this page has a follow up on setting where to use these options in XCode (all though it’s a bit old so the menus will probably be different): http://www.dribin.org/dave/blog/archives/2009/11/15/rpath/

Hope that helps!

Thanks for the links and info gregab.

I was able to get the dylibs loaded and working by doing two things:

  1. adding to the run script under Targets / Build Phases
  
# copy libfmodex.dylib to package target directory so self contained  
cp -f ../../../libs/fmodex/lib/osx/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libfmodex.dylib";  
# change orig path of ./libfmodex.dylib   
install_name_tool -change ./libfmodex.dylib @executable_path/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME";  
# copy libs3decoder.dylib to package target directory so self contained  
cp -f ../../../addons/ofxASR/libs/sphinx/lib/osx/libs3decoder.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libs3decoder.dylib";  
#  Optional - seems to work with or without it  - change orig path of ./libfmodex.dylib   
install_name_tool -change ./libs3decoder.dylib @executable_path/libs3decoder.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME";  
# copy libsphinxbase.dylib to package target directory so self contained  
cp -f ../../../addons/ofxASR/libs/sphinx/lib/osx/libsphinxbase.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libsphinxbase.dylib";  
#  Optional - seems to work with or without it  - change orig path of  @executable_path/libfmodex.dylib to target directory  
install_name_tool -change ./libsphinxbase.dylib @executable_path/libsphinxbase.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME";  

I am presuming that this copies the dylibs to the contents/MacOS folder of the package. The actual install_tool_change command seems optional in my case I believe because the dylib path is already

  
@executable_path/libs3decoder.dylib  

  1. dragging the dylib to the root of the Xcode project in the left side file hierarchy window in Xcode. I assume this if giving the linker the path to the libs during compile time …

Even though it is working I am still interested in if this is “standard procedure” for how one should deal with dylibs in open frameworks? It seems to break the desire to “copy the add-on to the add-on folder and then use project generator to make a generic project that has all the necessary links”…

Thanks again.

Hi Eltoro
Thanks so much for this explanation. It was exactly what I was struggling with and was looking for.
Haven’t tested it extensively (like on other machines) but I used it with MediaInfo dylib and I think it worked just fine.
Many thanks
fakob