qtopencvffmpegmacdeployqt

Deploying QT project with opencv and ffmpeg dylib error


When I build my project using the opencv and ffmpeg dylibs my application crashes upon opining with the error:

Dyld Error Message: Library not loaded: /usr/local/Cellar/ffmpeg/4.1.3/lib/libswresample.3.dylib

Referenced from: /Applications/myApp.app/Contents/Frameworks/libavcodec.58.dylib Reason: image not found

I have tried using the install_name_tool to try and change the paths using this:

install_name_tool -change libavcodec.58.dylib 

@executable_path/../Frameworks/libavcodec.58.dylib

/Users/me/code/build_output/MyAppQML/myApp.app/Contents/MacOS/myApp

Although this modified the file I was still getting the same error and crash at run time.

Is install_name_tool suitable to fix this issue or should I be looking at something else?

I've used otool on libavcodec.58.dylib which showed that some of the paths where linked to the @executable_path

@executable_path/../Frameworks/libavcodec.58.dylib (compatibility version 58.0.0, current version 58.35.100)
    /usr/local/Cellar/ffmpeg/4.1.3/lib/libswresample.3.dylib (compatibility version 3.0.0, current version 3.3.100)
    /usr/local/Cellar/ffmpeg/4.1.3/lib/libavutil.56.dylib (compatibility version 56.0.0, current version 56.22.100)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.60.2)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    @executable_path/../Frameworks/liblzma.5.dylib (compatibility version 8.0.0, current version 8.4.0)
    @executable_path/../Frameworks/libopencore-amrwb.0.dylib (compatibility version 1.0.0, current version 1.3.0)

Solution

  • Fixed by using:

    install_name_tool -change /usr/local/Cellar/ffmpeg/4.1.3/lib/libswresample.3.dylib 
    
    @executable_path/../Frameworks/libswresample.3.dylib
    
    /Users/me/code/build_output/MyAppQML/myApp.app/Contents/Frameworks/libavcodec.58.dylib
    

    Thanks for the pointer @L. Scott Johnson