Conflict between dynamic linking priority in OSX?

眉间皱痕 提交于 2019-11-27 04:06:50

You should not set library paths using DYLD_LIBRARY_PATH. As you've discovered, that tends to explode. Executables and libraries should have their library requirements built into them at link time. Use otool -L to find out what the file is looking for:

$ otool -L /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO:     /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO (compatibility version 1.0.0, current version 1.0.0)     ...     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1) 

For an example of one of my homebrew-built programs:

$ otool -L /usr/local/bin/gifcolor /usr/local/bin/gifcolor:     /usr/local/Cellar/giflib/4.1.6/lib/libgif.4.dylib (compatibility version 6.0.0, current version 6.6.0)     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0) 

Note that it references /usr/local. If you've built it in such a way that it references the wrong library, I recommend rebuilding and pointing it to the correctly library.

If that's impossible, it is possible to edit what path is used using install_name_tool, but there are cases where this doesn't work, such as if the new path is longer than the old path and you didn't link it with -header_pad_max_install_names. Rebuilding with the correct path is preferred.

Note that there are a few "special" paths available that allow libraries to be found relative to their loader. See @executable_path/ and its kin in the dyld(1) man page.

mdemirst

I experienced similar problem while using OpenCV in MacOS El Capitan. Solved the problem using the solution in the link

Solution is to delete some dlylibs in the /usr/local/lib directory and create symbolic links to related files /System/Library/Frameworks/ImageIO.framework/Resources/

cd /usr/local/lib rm libgif.dylib ln -s /System/Library/Frameworks/ImageIO.framework/Resources/libGIF.dylib libGIF.dylib rm libjpeg.dylib ln -s /System/Library/Frameworks/ImageIO.framework/Resources/libJPEG.dylib libJPEG.dylib rm libtiff.dylib ln -s /System/Library/Frameworks/ImageIO.framework/Resources/libTIFF.dylib libTIFF.dylib rm libpng.dylib ln -s /System/Library/Frameworks/ImageIO.framework/Resources/libPng.dylib libPng.dylib 

I had a similar error when trying to run Apache Celix on macOS Sierra If you use Homebrew to install libjpeg, libtiff, libpng which may confuse the linker to use macOS imageIO library. Simple fix is unlink those libs:

brew unlink libpng brew unlink libtiff brew unlink libjpeg 

Re-link those libs whenever we need to:

brew link libpng brew link libtiff brew link libjpeg 

If using Qt Creator, you have to uncheck the Add build library search path to DYLD_LIBRARY_PATH and DYLD_FRAMEWORK_PATH option from the Run section in the Projects tab:

I had a similar error, and i solved putting the following variable in my bash_profile:

export DYLD_LIBRARY_PATH=/usr/lib/:$DYLD_LIBRARY_PATH 

I followed the instructions mdemirst suggested and it fixed my issue. I am using OS X Sierra.

I created a gist just in case someone else runs into the same issue.

Gist to fix Spidermonkey errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!