Dynamic Libraries for OSX addon

I ve made an addon for real time audio analysis wrapping the Essentia library (http://essentia.upf.edu/).

Here is the repo: https://github.com/leozimmerman/ofxAudioAnalyzer

The thing is that Essentia uses a lot of audio libraries. Ive tried to design the addon so you dont need to install all the libraries in the system, but Im having some problems with the dylib files.
When trying to run examples in a pc with no libraries install on the system this error shows:

dyld: Library not loaded: /usr/local/Cellar/ffmpeg/2.1.4/lib/libavfilter.3.dylib
Referenced from: /usr/lib/libavdevice.55.5.100.dylib
Reason: image not found

It seems to be searching the libraries in the systems directory.
Does anyone know if its possible to link this libraries from the addon directory without need to install them on the system?

Hi @lzmmrman. I’m not exactly sure what you’re trying to do, but here’s some reading on paths for linking dynamic libraries.



These were helpful to me when I was dealing with some Framework/dylib stuff from the Myo SDK, which also has some helpful info:


1 Like

Hi mattfelsen, thanks for the info, I think it solves my problem.
The thing i was wondering is if it is possible to use dynamic libraries (dylib files) in an Easy to Use addon.

Ive succesfully wrapped the Essentia audio library (http://essentia.upf.edu/) with OF:

The issue is that you need to install de Essentia libraries and dependencies in the system in order to use the addon. (Xcode project is linked to /usr/local/libs)
I wanted library files in the addon directory to avoid Essentia installation, but if its complicated to link them in every new project maybe its better to leave as it is.

Oh, sorry, I thought you were trying to link against a library installed on the user’s system (in /Library/Frameworks for example), but now I see you mean that you want to package the library with the addon so that the user doesn’t have to install anything other than the addon itself.

It is definitely possible to package the pre-compiled libraries. Generally libs for OF addons are compiled as static (.a) rather than dynamic (.dylib, .dll) – I’m not sure if there’s a reason behind that or it’s just become the norm – but I don’t see why you couldn’t package them as dynamic libs as well. There’s info here on the file structure to use to package libs for multiple platforms, and a nice example:


Also pinging @theborg who has been interested in Essential as well:

Sorry to re-open this old thread.
I am trying to use a dynamic library (.dylib) on osx and I am not sure how to write a proper addon_config.mk.
Could someone give me an example how to do this? I did not find any documentation dealing with dynamic libraries. Using a static lib is not an option.


I hope this can help you.

Thanks for the link, it is not really what i am looking for. I am having an external dylib, I want to bundle with an addon and use in my app.

I am getting the following error:

dyld: Library not loaded: @rpath/libndi.dylib
  Referenced from: /Users/thomasgeissl/projects/dlr/openFrameworks/addons/ofxNDI/example-receiveVideo/bin/example-receiveVideo_debug.app/Contents/MacOS/example-receiveVideo_debug
  Reason: image not found

I am using Qt creator, 0.9.8. and/or the makefiles.

I tried adding
ADDON_LDFLAGS += -lndi -L/path/to/lib
ADDON_LIBS += /path/to/lib/libndi.dylib

Any pointers?

dylibs can be tricky if they are compiled to be loaded from a specific location.
In this case though it looks fine.

I think the only thing you are missing is to add the dylib to the copy files build phase of the Xcode project.

Something similar to this:

But with the dylib being added instead of a framework.
You might also need to change the destination from frameworks to executable path.

If neither work - you might need to add a definition for rpath ( which is compiled into the dylib ) as described here:

Thanks @theo, it works fine when generating the project via the project generator and using xcode. But qt creator and the makefiles did not work. i will check the link you have provided.

The same happend to me when trying to compile an ofxDarknet example via the makefiles. https://github.com/mrzl/ofxDarknet

Now it works when i run the app from xcode, but if i simply double click it in finder, it gives me the same error i get when i compile it with the make files. i try to fix this next week, if anyone has a solution please let me know.

I’m running into a very similar situation.
I’m trying to put together a very basic addon that uses a .dylib on OSX.
I’ve used ADDON_LDFLAGS to set the addons relative path to the .dylib file,
but when I run otool -L on the executable I can see it’s still linking against the absolute system path (/usr/local/lib) instead of the of addon relative path.

Any tips on setting up addon_config.mk to link against an addon local .dylib instead of a system one ?

Thank you,

This is absolutely one of pain when we make addon for OSX with dylib.

For standalone app package, we need to copy dylib and use install_name_tool.
(following is how oF manage libfmod.dylib in Xcode project ->Run Script phase)

rsync -aved "$OF_PATH/libs/fmodex/lib/osx/libfmodex.dylib" "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/";
install_name_tool -change @executable_path/libfmodex.dylib @executable_path/../Frameworks/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME";

Another option is this simple but super cool tool dylibbundler
dylibbundler automatically resolves shared lib dependency and copy dylib to inside of .app package. I tested and works amazing.

Here is sample command

$ cd yourCoolProject/bin
$ dylibbundler -od -b -x ./yourCoolProject.app/Contents/MacOS/yourCoolProject -d ./yourCoolProject.app/Contents/libs

You will be asked where is libfmodex.dylib but we can simply pass relative path like below.

'$ ./yourCoolProject.app/Contents/Frameworks'

*Of course please install dylibbunder before execute command above.


hey @hrs, I am getting crashes (quits unexpectedly in another machine) when open the app too.
If I add my signing i get the error too:

/Users/myUser/Documents/openFrameworks/apps/19/ReceptiveCube/bin/ReceptiveCube.app: code object is not signed at all

In subcomponent: /Users/myUser/Documents/openFrameworks/apps/19/ReceptiveCube/bin/ReceptiveCube.app/Contents/Frameworks/libfmodex.dylib
Command /usr/bin/codesign failed with exit code 1

I installed dylibbundler like you said.

So we need to comment the Xcode project -> (build phases) Run Script phase lines and the to apply the dylibbundler command. That’s right?

Btw I tried with and without commenting too… and then I applied the command. It shows the error, but outside Xcode I can run the script to add the lib. But stills not working in another machine.

If app runs on your machine but does not run in another machine, I think it is because of translocation. Try to search this forum with keyword “translocation”.

1 Like