赞
踩
在Mac OS 10.++上,有的时候应用程序找不到动态库。例如在使用ffplay播放视频的时候:
ffplay ~/Movies/testfile.mp4
得到的错误:
- dyld: Library not loaded: /usr/local/opt/sdl/lib/libSDL-1.2.0.dylib
- Referenced from: /usr/local/bin/ffplay
- Reason: image not found
利用工具otool查看ffplay依赖的动态库:
- otool -L /usr/local/bin/ffplay
-
-
- /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
- /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1404.47.0)
- /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
- /System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0)
- /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1259.0.0)
- /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0)
- /System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
- /System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0, current version 1.0.0)
- /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1258.1.0)
- /System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox (compatibility version 1.0.0, current version 1.0.0)
- /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 492.0.0)
- /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
- /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
- /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 57337.60.2)
- /usr/local/opt/sdl/lib/libSDL-1.2.0.dylib (compatibility version 12.0.0, current version 12.4.0)
- /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 22.0.0)
- /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 600.0.0)
- /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
- /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
- /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
- /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 728.13.0)
- /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage (compatibility version 1.0.1, current version 2.0.0)
- /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
发现libSDL-1.2.0.dylib的查找路径为:/usr/local/opt/sdl/lib/libSDL-1.2.0.dylib (compatibility version 12.0.0, current version 12.4.0)
然而我的实际路径为:/usr/local/sdl1_2_15/lib/libSDL-1.2.0.dylib (compatibility version 12.0.0, current version 12.4.0)
自然就找不到了。。。
使用工具install_name_tool来修改应用程序对动态库的查找路径,用法:
install_name_tool oldpath newpath /path2APP/appName
针对前面的问题,使用如下命令就OK了。
install_name_tool -change /usr/local/opt/sdl/lib/libSDL-1.2.0.dylib /usr/local/sdl1_2_15/lib/libSDL-1.2.0.dylib /usr/local/bin/ffplay
还有个问题,如果出现错误如下:
- dyld: Library not loaded: @rpath/libopencv_shape.3.2.dylib
- Referenced from: /Users/******/Library/Developer/Xcode/DerivedData/imageEnhance-bjagxbzymzhmlkflyuypxbrechtu/Build/Products/Release/imageEnhance
- Reason: image not found
说明运行时没有找到相应的库,那么在Runpath Search Paths中设置所需要的库的路基即可,如下图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。