当前位置:   article > 正文

install_name_tool解决dyld: Library not loaded_install_name_tool详细用法

install_name_tool详细用法

在Mac OS 10.++上,有的时候应用程序找不到动态库。例如在使用ffplay播放视频的时候:

ffplay ~/Movies/testfile.mp4 
  • 1
  • 1

得到的错误:

  1. dyld: Library not loaded: /usr/local/opt/sdl/lib/libSDL-1.2.0.dylib
  2. Referenced from: /usr/local/bin/ffplay
  3. Reason: image not found
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

利用工具otool查看ffplay依赖的动态库:

  1. otool -L /usr/local/bin/ffplay
  2. /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
  3. /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1404.47.0)
  4. /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
  5. /System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0)
  6. /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1259.0.0)
  7. /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0)
  8. /System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
  9. /System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0, current version 1.0.0)
  10. /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1258.1.0)
  11. /System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox (compatibility version 1.0.0, current version 1.0.0)
  12. /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 492.0.0)
  13. /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
  14. /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
  15. /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 57337.60.2)
  16. /usr/local/opt/sdl/lib/libSDL-1.2.0.dylib (compatibility version 12.0.0, current version 12.4.0)
  17. /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 22.0.0)
  18. /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 600.0.0)
  19. /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
  20. /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
  21. /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
  22. /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 728.13.0)
  23. /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage (compatibility version 1.0.1, current version 2.0.0)
  24. /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

发现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
  • 1
  • 1

还有个问题,如果出现错误如下:

  1. dyld: Library not loaded: @rpath/libopencv_shape.3.2.dylib
  2. Referenced from: /Users/******/Library/Developer/Xcode/DerivedData/imageEnhance-bjagxbzymzhmlkflyuypxbrechtu/Build/Products/Release/imageEnhance
  3. Reason: image not found
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

说明运行时没有找到相应的库,那么在Runpath Search Paths中设置所需要的库的路基即可,如下图: 
这里写图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/109540
推荐阅读
相关标签
  

闽ICP备14008679号