Unsolved Creating .dmg for Qt app mac OSX
-
I see so many questions and posts asking about this, and almost everywhere I see the op being asked to refer to http://doc.qt.io/qt-5/osx-deployment.html
But the problem for someone who is new to Qt is difficult to understand there how to generate the dmg file.
Let's not go in depth of having external libraries, plugins etc in a project.
If we create a totally new QWidget program, without a single line of code, the default project that just shows a window, then how will someone generate the dmg file.
If we do
macdeployqt yourProjectName.app -dmg
inside the debugbuild
folder, without doing anything then it will of course create dmg file but it fails to open and now if you try to run the default project then will face this error :This application failed to start because it could not find or load the Qt platform plugin "cocoa" in "". Available platform plugins are: cocoa. Reinstalling the application may fix this problem. The program has unexpectedly finished.
So, what is the process of generating a working dmg file for a Qt application?
-
This should work. Clearly it doesn't in your case.
The first thing I would do is run macdeployqt without the -dmg option and create your application to verify the layout is correct. You should see it populated with copies of the whatever is required to run. Specifically for the cocoa plugin you should be able to find 'YourAppName.app/Contents/Plugins/platforms/libqcocoa.dylib'.
Are you running macdeployqt on a release build of your program? The debug version should work but it will have different dependencies (and be a lot bigger than it needs to be).
If you run macdeployqt on an application you cannot (should not) run it a second time. The first pass changes the relative path entries of the files so a second pass will end up not recognizing these (which means it won't add missing libraries at a minimum).
Maybe there is some option you have in your program or project file that has altered the location where plugins are loaded from? Maybe some sort of odd Info.plist file?
If you were to create a listing of the directory structure of your application this would probably be helpful. I included an example of one I have handy (created using macdeployqt by the way):
some_application.app └── Contents ├── Frameworks │ ├── QtCore.framework │ │ ├── QtCore -> Versions/Current/QtCore │ │ ├── Resources -> Versions/Current/Resources │ │ └── Versions │ │ ├── 5 │ │ │ ├── QtCore │ │ │ └── Resources │ │ │ └── Info.plist │ │ └── Current -> 5 │ ├── QtDBus.framework │ │ ├── QtDBus -> Versions/Current/QtDBus │ │ ├── Resources -> Versions/Current/Resources │ │ └── Versions │ │ ├── 5 │ │ │ ├── QtDBus │ │ │ └── Resources │ │ │ └── Info.plist │ │ └── Current -> 5 │ ├── QtGui.framework │ │ ├── QtGui -> Versions/Current/QtGui │ │ ├── Resources -> Versions/Current/Resources │ │ └── Versions │ │ ├── 5 │ │ │ ├── QtGui │ │ │ └── Resources │ │ │ └── Info.plist │ │ └── Current -> 5 │ ├── QtPrintSupport.framework │ │ ├── QtPrintSupport -> Versions/Current/QtPrintSupport │ │ ├── Resources -> Versions/Current/Resources │ │ └── Versions │ │ ├── 5 │ │ │ ├── QtPrintSupport │ │ │ └── Resources │ │ │ └── Info.plist │ │ └── Current -> 5 │ └── QtWidgets.framework │ ├── QtWidgets -> Versions/Current/QtWidgets │ ├── Resources -> Versions/Current/Resources │ └── Versions │ ├── 5 │ │ ├── QtWidgets │ │ └── Resources │ │ └── Info.plist │ └── Current -> 5 ├── Info.plist ├── MacOS │ └── some_application ├── PkgInfo ├── PlugIns │ ├── imageformats │ │ ├── libqdds.dylib │ │ ├── libqgif.dylib │ │ ├── libqicns.dylib │ │ ├── libqico.dylib │ │ ├── libqjpeg.dylib │ │ ├── libqtga.dylib │ │ ├── libqtiff.dylib │ │ ├── libqwbmp.dylib │ │ └── libqwebp.dylib │ ├── platforms │ │ └── libqcocoa.dylib │ └── printsupport │ └── libcocoaprintersupport.dylib └── Resources ├── icons.icns └── qt.conf 38 directories, 31 files
-
Hi,
First and foremost, what version of Qt are you using ? On what version of macOS ? And which version of Xcode ?
Do you get any error message when you run macdeployqt ?
-
@Rondog Thanks for the answer. I am really struggling with this problem since 24th August.
As you said, I ran
macdeployqt yourProjectName.app
without the-dmg
and yes, the project didn't run after that.
The project structure that you showed, I went through my Contents folder and its almost the same, I don't know why this is happening.I have uploaded my Content folder : https://github.com/torrtuga/QTAppContent
I am really not getting any sense where am I going wrong, as its the default that I am doing.
QT Creator : 5.10.0
Mac OSX : OSX 10.12 Sierra -
I had a look at your app. It almost runs (returns an error EXC_CRASH (SIGABRT) ).
After some investigation it looks like you are missing a library that is needed by libqcocoa.dylib. When I run the command otool -L libqcocoa.dylib I see this:
@rpath/../plugins/platforms/libqcocoa.dylib (compatibility version 0.0.0, current version 0.0.0) /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 21.0.0) /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 157.0.0) /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0) /usr/lib/libcups.2.dylib (compatibility version 2.0.0, current version 2.11.0) /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0) ***** @rpath/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8) ***** /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 48.0.0) /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1343.14.0) /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0) @rpath/libQt5PrintSupport.5.dylib (compatibility version 5.6.0, current version 5.6.2) @rpath/libQt5Widgets.5.dylib (compatibility version 5.6.0, current version 5.6.2) @rpath/libQt5Gui.5.dylib (compatibility version 5.6.0, current version 5.6.2) @rpath/libQt5Core.5.dylib (compatibility version 5.6.0, current version 5.6.2) /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1151.16.0) /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 62.0.0) /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1151.16.0) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
I could not find libz.1.dylib in your app bundle. When libcocoa.dylib tries to load it can't find this library and this is probably where things go bad (?).
-
@SGaist
QT Creator : 5.10.0
Mac OSX : OSX 10.12 Sierra
I have uploaded my Contents folder also if its of any help in the other post here. -
Just to add a bit more information...
If you set the environment variable QT_DEBUG_PLUGINS=1 and run the executable file directly you can see more of what is going on:
export QT_DEBUG_PLUGINS=1 ./test_app.app/Contents/MacOS/DMGCheckQT QFactoryLoader::QFactoryLoader() checking directory path "/Users/ron/Downloads/test_app.app/Contents/PlugIns/platforms" ... QFactoryLoader::QFactoryLoader() looking at "/Users/ron/Downloads/test_app.app/Contents/PlugIns/platforms/libqcocoa.dylib" Found metadata in lib /Users/ron/Downloads/test_app.app/Contents/PlugIns/platforms/libqcocoa.dylib, metadata= { "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3", "MetaData": { "Keys": [ "cocoa" ] }, "className": "QCocoaIntegrationPlugin", "debug": false, "version": 329218 } Got keys from plugin meta data ("cocoa") QFactoryLoader::QFactoryLoader() checking directory path "/Users/ron/Downloads/test_app.app/Contents/MacOS/platforms" ... Cannot load library /Users/ron/Downloads/test_app.app/Contents/PlugIns/platforms/libqcocoa.dylib: (dlopen(/Users/ron/Downloads/test_app.app/Contents/PlugIns/platforms/libqcocoa.dylib, 133): Library not loaded: @rpath/libQt5PrintSupport.5.dylib Referenced from: /Users/ron/Downloads/test_app.app/Contents/PlugIns/platforms/libqcocoa.dylib Reason: image not found) QLibraryPrivate::loadPlugin failed on "/Users/ron/Downloads/test_app.app/Contents/PlugIns/platforms/libqcocoa.dylib" : "Cannot load library /Users/ron/Downloads/test_app.app/Contents/PlugIns/platforms/libqcocoa.dylib: (dlopen(/Users/ron/Downloads/test_app.app/Contents/PlugIns/platforms/libqcocoa.dylib, 133): Library not loaded: @rpath/libQt5PrintSupport.5.dylib\n Referenced from: /Users/ron/Downloads/test_app.app/Contents/PlugIns/platforms/libqcocoa.dylib\n Reason: image not found)" This application failed to start because it could not find or load the Qt platform plugin "cocoa" in "". Available platform plugins are: cocoa. Reinstalling the application may fix this problem. Abort trap: 6
Note: You seem to be missing the Qt5PrintSupport framework which is why the cocoa plugin is not loading. Is this included in your project (PRO) file by chance?
greaterThan(QT_MAJOR_VERSION, 4): { QT += widgets printsupport }
I know this is a one widget test program so you probably don't have this but, for some reason, it is shown as a dependency.
-
@Rondog Hi,
I did runotool -L libz.1.dylib
and found the following output :libz.1.dylib: /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
Regarding the
libz.1.dylib
how can I get it right as its there in my/usr/lib
folder. In this whole process I didn't do anything special from my side and followed QT guidelines to create a new project.
While starting a new project I select the following :
By defaultQt 5.9.1 clang 64bit2
is also selected, I uncheck that and go with only first option.I added
QT += widgets printsupport
in my .pro file, but I can't find any way to get the compatible version forlibz.1.dylib
, so still the same problem I get.I have uploaded the whole project(which is not running now because
macdeployqt DMGTestFinal.app
is executed) over here : https://github.com/torrtuga/DMGCheckQTAppI really hope if this
libz.1.dylib
problem is solved then I am able to create a working dmg file, as this is really becoming painful since so many days.
Also, myQT
is a free trial version :Available under GPL & LGPLv3 licenses
-
@Arqam Qt 5.10 is still in its experimental alpha version! It is highly likely, that the macdeployment tool is not jet up to date.
Build your app for 5.9, run the macdeploy tool of the 5.9 folder and see if that doesn't fix your problems.
-
@J.Hilk No, its the same result in both cases.
-
Run
otool -L
on all plugins involved to see what might be going on. -
I think I know how to fix your problem (or pretty sure at least).
What is happening is macdeployqt is looking at the path and thinks it is a system file so it is not added to your application (app). I believe the libz.1.dylib is part of zlib and you happen to have it installed in /usr/lib/. I am not sure how it was linked to your plugins but this is less important (but could be the other solution - remove this dependency from your plugins).
You will need to modify the source of macdeployqt to fix your problem. From the Qt sources you will find the macdeployqt program and file of interest here: qt-everywhere-opensource-src-5.x.x/qttools/src/macdeployqt/shared/shared.cpp You need to add an exception to allow /usr/lib/libz.1.dylib
The function 'parseOtoolLibraryLine(...)' checks the path and (very correctly) doesn't include anything that is likely a system file. In your case /usr/lib/libz.1.dylib is thought to be a system library so it is not included. I am using Qt 5.6.0 and I know you have 5.10.x so there may be some differences in what I posted for source but i suspect they are small.
I actually ran into this problem as well. I compiled Qt from sources and installed it in /usr/lib/qt5 using the -prefix option. I know this is not the right place on OSX but it is a location I have used on GNU/Linux and simply stuck with it. I added an exception to the above mentioned file (and function) so that anything starting with /usr/lib/qt5 was not rejected.
FrameworkInfo parseOtoolLibraryLine(const QString &line, const QString &appBundlePath, const QSet<QString> &rpaths, bool useDebugLibs) { FrameworkInfo info; QString trimmed = line.trimmed(); if (trimmed.isEmpty()) return info; // Don't deploy system libraries. if (trimmed.startsWith("/System/Library/") || (trimmed.startsWith("/usr/lib/") && trimmed.contains("libQt") == false) // exception for libQtuitools and libQtlucene || trimmed.startsWith("@executable_path") || trimmed.startsWith("@loader_path")) return info; ...
-
This post is deleted! -
@Rondog said in Creating .dmg for Qt app mac OSX:
5.10.x
I edited the
shared.cpp
file.The error that I get now is the following:
QFactoryLoader::QFactoryLoader() checking directory path "/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms" ... QFactoryLoader::QFactoryLoader() looking at "/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib" Found metadata in lib /Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib, metadata= { "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3", "MetaData": { "Keys": [ "cocoa" ] }, "className": "QCocoaIntegrationPlugin", "debug": false, "version": 329218 } Got keys from plugin meta data ("cocoa") QFactoryLoader::QFactoryLoader() checking directory path "/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/MacOS/platforms" ... Cannot load library /Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib: (dlopen(/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib, 133): Library not loaded: @rpath/libQt5PrintSupport.5.dylib Referenced from: /Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib Reason: image not found) QLibraryPrivate::loadPlugin failed on "/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib" : "Cannot load library /Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib: (dlopen(/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib, 133): Library not loaded: @rpath/libQt5PrintSupport.5.dylib\n Referenced from: /Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib\n Reason: image not found)" This application failed to start because it could not find or load the Qt platform plugin "cocoa" in "". Available platform plugins are: cocoa. Reinstalling the application may fix this problem. Abort trap: 6
I tried with both the lines in my
.pro
file :greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
as well as without
printsupport
but it gives the same error ofLibrary not loaded: @rpath/libQt5PrintSupport.5.dylib
Is it because of anything that I did? When I run
otool -L libcocoa.dylib
I get the following :libqcocoa.dylib: @rpath/../plugins/platforms/libqcocoa.dylib (compatibility version 0.0.0, current version 0.0.0) /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 21.0.0) /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 157.0.0) /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0) /usr/lib/libcups.2.dylib (compatibility version 2.0.0, current version 2.11.0) /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0) @rpath/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8) /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 48.0.0) /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1343.14.0) /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0) @rpath/libQt5PrintSupport.5.dylib (compatibility version 5.6.0, current version 5.6.2) @rpath/libQt5Widgets.5.dylib (compatibility version 5.6.0, current version 5.6.2) @rpath/libQt5Gui.5.dylib (compatibility version 5.6.0, current version 5.6.2) @rpath/libQt5Core.5.dylib (compatibility version 5.6.0, current version 5.6.2) /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1151.16.0) /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 62.0.0) /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1151.16.0) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
In the Framework folder I have these three only :
QtCore.framework QtGui.framework QtWidgets.framework
And what it is searching for is @rpath/libQt5PrintSupport.5.dylib and the library that I have in path :/Contents/PlugIns/printsupport
islibcocoaprintersupport.dylib
@Rondog Please mail me : So that I can reply as soon as you post. Email : arq.ahmad.arqam@gmail.com
-
I am not sure if I was clear about modifying the utility macdeployqt. After you change this program you need to compile it and make sure you are actually using the new version when it is used.
To add an exception for the libz.1.dylib the function parseOtoolLibraryLine(...) might end up looking like this:
FrameworkInfo parseOtoolLibraryLine(const QString &line, const QString &appBundlePath, const QSet<QString> &rpaths, bool useDebugLibs) { FrameworkInfo info; QString trimmed = line.trimmed(); if (trimmed.isEmpty()) return info; if(trimmed.startsWith("/usr/lib/libz.1.dylib") == false) // specifically allow this file. { // Don't deploy system libraries. if (trimmed.startsWith("/System/Library/") || (trimmed.startsWith("/usr/lib/") && trimmed.contains("libQt") == false) // exception for libQtuitools and libQtlucene || trimmed.startsWith("@executable_path") || trimmed.startsWith("@loader_path")) return info; } ...
After changing this file you need to compile it. From the directory of macdeployqt (i.e. qt-everywhere-opensource-src-5.x.x/qttools/src/macdeployqt) you need to compile from the terminal:
cd ~/<wherever you have the qt sources>/qttools/src/macdeployqt make
If you only have the sources and a precompiled version of Qt you probably need to do something like this to create the make files:
cd ~/<wherever you have the qt sources>/qttools/src/macdeployqt qmake make
You need to make sure that you are actually using the new compiled version when you run this program. You need to copy the new version to the location where you currently have the binary macdeployqt application or specify the full path to the executable when running it.
The end result of all this is that you should see the libz.1.dylib library somewhere in your app bundle.
The other item (libQt5PrintSupport.5.dylib) is something I did notice previously. One thing you could try is to copy the missing framework into the app (same layout as the other frameworks) and see if it makes a difference. I am not sure if the framework is adjusted like all the other executables (i.e. using @rpath/...) but it should be suitable as a test regardless if it is modified. It will tell you if you need to get this packaged with the rest of your app.
Note: When you run macdeployqt you can ask it for more details about what it is doing by adding the switch -verbose
-verbose=<0-3> : 0 = no output, 1 = error/warning (default), 2 = normal, 3 = debug
-
@Rondog Right now I am using the QT installed using the installer. I have generated the Src using Maintenance tool.
So when I make the QT src, will the QTCreator use the new library or the one that I got using QT installer already? -
@Arqam Somewhere on your computer you will have the binary version of macdeployqt that QtCreator is using (likely in the bin folder from wherever Qt is installed). After you compile the new version you need to make sure it ends up in the proper location. Just rename the old one and copy the new one in its place. You can do a search to find all copies of this binary just to be sure.
I assume QtCreator is not using its own version of macdeployqt. I am also assuming that you are only compiling macdeployqt. If you are thinking of compiling all of Qt this is a bit more work. I don't think you need to compile all of Qt (at least I would hope not).
-
Qt Creator uses the tools from the Qt version assigned to the Kit used to build the application.
And no, there's no need to re-build all of Qt to build only one module.
-
@Rondog
When I runqmake
I get the following :/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/Src/qttools/.qmake.conf:1: Cannot find feature qt_build_config Could not find qmake configuration file macx-clang. Error processing project file: /Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/Src/qttools/src/macdeployqt/macdeployqt.pro
And when I run
make
I get the following :
make: *** No targets specified and no makefile found. Stop.
Am I doing something wrong?
-
I am not sure how this should be done. I always download the sources and compile Qt for each OS that I plan to run on. For me it is as simple as opening a terminal window and entering the command 'make'.
If you open the macdeployqt program in QtCreator can you compile it from there?
Maybe try running the configure command from the folder qtbase of the source tree (this configures everything and creates all the make files) then run 'make' from the qttools folder.
There must be some notes somewhere about working with the sources from a pre-compiled version of Qt.