There is a dynamic-linking-conflict between different libjpeg dynamic libraries on OSX. First there is a standard native libJPEG.dylib (in /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/). But if you are using MacPorts, you can also have a port-related libjpeg.dylib in (in /opt/local/lib). The latter may for example have been installed as a dependency for some other port.
This creates a problem when you link against your system libJPEG (which is preferred).
Then if /opt/local/lib
is in DYLD_LIBRARY_PATH, that path will be prioritised when searching for a dynamic lib, resulting in a runtime error when loading symbols:
dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from:
/System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /opt/local/lib/libJPEG.dylib
in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Trace/BPT trap: 5
So I have two questions (likely related):
What is a good way of solving the actual problem (removing
/opt/local/lib
fromDYLD_LIBRARY_PATH
obviously solves it but creates problems for other dependencies)?What other paths are searched for dynamic libs (I.e. Where is the "/System/Library" path specified) and why does DYLD_LIBRARY_PATH rank higher priority-wise?
otool
andinstall_name_tool
are useful indeed. The reason for why I am not using the full path for all libraries when linking is because the binary will be distributed to systems without brew or ports. I would like to use system libraries as much as possible and the remaining libraries will be packaged with the app. But during development the directory structure looks different than that of the installed app, so I link non-system libraries with relative paths (as in the version to be distributed), but have /opt/local/ in DYLD until I'm ready for release/packaging. – Lichenin