4

I am facing difficulty while deploying QT app which is using openCV as an external library.

In http://doc.qt.io/qt-5/osx-deployment.html page it says : To include a 3rd party library in the application bundle, copy the library into the bundle manually, after the bundle is created. So where should I copy inside the.app folder?

Also http://www.dafscollaborative.org/opencv-deploy.html blog is saying to use install_name_tool to deploy openCV with Qt app, but the path that he is using is not clear to me and its giving error in my case.

So, what should I do to deploy my QT app with opencv library?

Running otool -L MyApplication.app/Contents/MacOS/MyApplication gives me following :

@rpath/libopencv_calib3d.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_features2d.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_highgui.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_videoio.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_imgcodecs.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_video.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_photo.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_ml.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_imgproc.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_flann.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_core.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.10.0, current version 5.10.0)
@rpath/QtGui.framework/Versions/5/QtGui (compatibility version 5.10.0, current version 5.10.0)
@rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.10.0, current version 5.10.0)
/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
@rpath/QtXml.framework/Versions/5/QtXml (compatibility version 5.10.0, current version 5.10.0)
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)
Farhad
  • 4,119
  • 8
  • 43
  • 66
arqam
  • 3,582
  • 5
  • 34
  • 69
  • what error are you getting with the openCV library you're including with your app? – Michael Dautermann Sep 07 '17 at 11:26
  • @MichaelDautermann Its working fine with my local system, but when I share the dmg to other non qt, non opencv system to run, there it doesn't even start when double clicked. – arqam Sep 07 '17 at 11:33
  • The first link is dead and has been replaced by https://doc.qt.io/qt-5/macos-deployment.html – Greenonline Aug 08 '21 at 09:15

2 Answers2

4

In macOS, a dylib has an embedded path to where it expects to be placed in the file system. Applications linking against those dylibs will expect to find the dylib in that location. This is the path that you can modify with install_name_tool and inspect with otool -L.

@rpath is a placeholder that represents the runtime path of the application linking against the dll. The runtime path of the application is set by passing the -rpath flag to the linker. The runtime path itself can use the placeholder @executable_path, with which you can set paths relative to the executable.

In your case, if you set -rpath @executable_path/../Frameworks, you must copy the Qt libraries to the Frameworks folder inside the application bundle for your application to find them.

Stefan Werner
  • 440
  • 2
  • 7
  • Can you please give an example of command to write when linking the library after we copy it to the Framework folder. – arqam Sep 07 '17 at 12:48
  • You don't have to copy before linking, it's fine to link before the copy step happens. The location of the dylib while linking has no influence, what matters is the install name path. If you're asking for an example of a linker command that uses @rpath, there's one in the answer for this question: https://stackoverflow.com/questions/27506450/clang-change-dependent-shared-library-install-name-at-link-time – Stefan Werner Sep 10 '17 at 07:27
3

I don't know if you have found the answer but here is a solution:

After compiling your application, you have a bundle. Use macdeployqt to embed Qt frameworks in your bundle.

After that, open your bundle, go to Contents/Frameworks, you must have all necessary Qt Frameworks here. Simply add your opencv libraries here.

Your bundle now contains everything needed.

Regards

Benoît
  • 31
  • 2