Trouble with dylib's

EDIT : (rewriting the question)

I am linking a dylib into an XCode project.
I’m just using the default settings from Project Generator

When the application starts, it crashes out:

I’m wondering what the best way is to get this working?
I’m aiming for the addon to have project generator compatibility

I’ve tried:

  1. Manually copying in the dylib files into a number of locations inside the app package
  2. Adding the dylib files to ‘Embedded Binaries’

I’m not very experienced with oF+XCode recently, so any hints are welcome.

Thank you

I got a little hint from

I changed the install name with the command

install_name_tool -id “@loader_path/libceres.2.0.0.dylib” libceres.2.0.0.dylib

and copied the dylib into the Contents/MacOS folder of the application bundle manually. That seems to work. Searching for a cleaner option…

i did the same as elliot by adding a build phase in xcode.

cp $OF_PATH/addons/ofxNDI/libs/libndi/lib/osx/libndi.dylib $TARGET_BUILD_DIR/$
install_name_tool -change @rpath/libndi.3.dylib @executable_path/libndi.3.dylib $PRODUCT_NAME
1 Like

When you compile a lib for OSX you can set the path for the app to look for the lib, it can be @executable_path, @loader_path, or @rpath. The install name change tool will take care of discrepancies, but if you would prefer a path that is friendly to the project generator you would have to recompile the lib.

Some info:,@load_path_and@rpath

Ha. I was dealing with this same thing, although I’ve been looking on how to make this process automagically without need for changing any setting in xcode

If you select the project in the left pane navigator and then go to Build Phases you can add a script as @thomasgeissl describes. In there you’ll find that there are other scripts and in one there is how libfmodex is copied and linked (yeah, this lib it is still being used.!). notice that rsync is used instead of cp to avoid unnecesary spent time copying something that might be already there.

Another option is to have the library installed “globally” on your computer or simply have it in your addons folder and not copying into the app bundle, and not using install_name_tool. For this you need to set the rpath in the Build Settings put the absolute path to the folder that has the libraries
in the Runpath Search Paths field.

I’ll bring some news if I find anything interesting.


1 Like

Thanks for the help all!

thanks! is there a way to add such a build phase setting into the project generator?

As far as I can tell, the project generator cannot assign any setting to the project which copies the dylib into the app package. Therefore there is no path which is friendly to project generator since the file simply isn’t there (unless you go for absolute paths / system paths, which any built app non-portable).

Thanks for the tips. It seems that using the ‘Embedded Binaries’ setting is as good as rsync (so long as you’re happy with the resulting dylib location)

And yes - it was working with global install at first, which isn’t great because it’s non-portable.

I guess for the time being I just need to add something to the readme about copying libs and give up on auto-project generator.

or add this feature to PG. :slight_smile:

It think it would be super useful to be able to specify these post build scripts in it. I’ll take a look and let you know if I make any improvements.

I thought this was there, but it’s onlu working for windows. I’ve included some missing flags in the template:

ADDON_DLLS_TO_COPY allows to copy dlls from the addon folders to the executable folder or the bundle in the case of osx. I thought there was also an ADDON_AFTER that runs a script after the addon is installed but i think it only works with the makefiles right now.


Aha, that is great, I thought it was just my ineptitude that was stopping the PG do this kind of copy for OSX. Hence the tip above for @elliotwoods.

Just a quick and dirty hack for this to work.

Open this addons file and add the following line

ADDON_LDFLAGS =  -rpath /path/to/your/openFrameworks/folder/addons/ofxWhatever/libs/path/to where/the/dylib/files/are 

by changing where it says /path/to/your/openFrameworks/folder/addons/ofxWhatever/libs/path/to where/the/dylib/files/are for the absolute path to the folder that contains the dylibs. It is important that this is the absolute path.

If you are not sure about the absolute path of this folder, an easy trick is to open the terminal (type terminal on the spotlight search and press enter) and drag and drop the folder with the dylibs into the terminal window that you just opened. There it will show the absolute path to the folder you just dragged, select that text copy and paste into . :slight_smile:

@arturo ADDON_DLLS_TO_COPY does not seem to work on osx. I’ll take a look at it later.

1 Like

it would be great to have a way of inputting a relative path there, so the addon could run in other machines.
I’ve just noticed ofxHapPlayer uses

	ADDON_LDFLAGS = -rpath @loader_path/../../../../../../../addons/ofxHapPlayer/libs