Dyld: Library not loaded: ... Reason: image not found



I try to link to a dynamic library on MacOS - but couldn’t figure out what information I would have to add to the Projucer in order to make the executable find the library. I suppose that I would have to add some @rpath and @loader_path linker flags in the “Config > Xcode > Extra linker flags” field - but whatever I tried, it wouldn’t work…

When copying libantlr4-runtime.dylib into the directory of the executable (Builds/MacOSX/build/Debug) and starting it from the same directory via the command line everything works. But there should be some better way to proceed…

Here the error I get:

dyld: Library not loaded: libantlr4-runtime.dylib
Referenced from: /Users/dietrich/home/cs/lang/compiler/antlr/projects/cpp/2017-05-08.cpp-demo/000/demo/Builds/MacOSX/build/Debug/demo
Reason: image not found

There are a number of other postings concerning this topic, but none provided a working solution. So I decided to ask once again…

Thanks for your help,

Regards, Dietrich


Here is a good read-up on @rpath and friends:


One thing to remember is that you must set the install name to include @rpath when building the dynamic library. Only then will the @rpath portion of the install-name be replaced with whatever you specify in your -rpath option when linking your app. So switching to @rpaths will usually involve re-linking both the dynamic lib and the application.