My application crashes when trying to run the final .app of my project once built on MacOS: "Could not load the Qt platform plugin "cocoa" in "" even though it was found." How can I solve it?
-
Hello.
I have built my application on MacOS and when I launch the final executable (.app file), the application crashes. If I try to run the application from terminal, I get the following output:
I run:
export QT_DEBUG_PLUGINS=1 ./MyApp
The output:
[2023-02-27 18:22:52.681] [info] [myapp.cpp:27] cURL version: libcurl/7.66.0 OpenSSL/1.1.1 zlib/1.2.11 [2023-02-27 18:22:52.682] [info] [myapp.cpp:31] Libuv version: 1.41.0 QFactoryLoader::QFactoryLoader() checking directory path "/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms" ... QFactoryLoader::QFactoryLoader() looking at "/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib" Found metadata in lib /Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib, metadata= { "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3", "MetaData": { "Keys": [ "cocoa" ] }, "archreq": 0, "className": "QCocoaIntegrationPlugin", "debug": false, "version": 331520 } Got keys from plugin meta data ("cocoa") QFactoryLoader::QFactoryLoader() checking directory path "/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/MacOS/platforms" ... Cannot load library /Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib: (dlopen(/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib, 0x0085): Library not loaded: @rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport Referenced from: <D4AB240B-4535-3AEC-B72B-5FFC4750E4E5> /Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib Reason: tried: '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtCore.framework/Versions/5/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/System/Volumes/Preboot/Cryptexes/OS@rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtCore.framework/Versions/5/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/System/Library/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file, not in dyld cache)) QLibraryPrivate::loadPlugin failed on "/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib" : "Cannot load library /Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib: (dlopen(/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib, 0x0085): Library not loaded: @rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport\n Referenced from: <D4AB240B-4535-3AEC-B72B-5FFC4750E4E5> /Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib\n Reason: tried: '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtCore.framework/Versions/5/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/System/Volumes/Preboot/Cryptexes/OS@rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtCore.framework/Versions/5/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/System/Library/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file, not in dyld cache))" qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: cocoa. zsh: abort ./MyApp
Main error:
qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
These are the things I have tried, without success:
- Reinstall Qt completely
- Build the project from scratch
Finally, here are some details of the project configuration:
- It is developed in Qt, C++ and built using cmake.
- I don't use Python
- I need to build the project to run on MacOS.
- Qt Version: 5.15.2
- The application runs perfectly if I run it from Qt Creator.
Thanks in advance :)
-
Hello.
I have built my application on MacOS and when I launch the final executable (.app file), the application crashes. If I try to run the application from terminal, I get the following output:
I run:
export QT_DEBUG_PLUGINS=1 ./MyApp
The output:
[2023-02-27 18:22:52.681] [info] [myapp.cpp:27] cURL version: libcurl/7.66.0 OpenSSL/1.1.1 zlib/1.2.11 [2023-02-27 18:22:52.682] [info] [myapp.cpp:31] Libuv version: 1.41.0 QFactoryLoader::QFactoryLoader() checking directory path "/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms" ... QFactoryLoader::QFactoryLoader() looking at "/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib" Found metadata in lib /Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib, metadata= { "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3", "MetaData": { "Keys": [ "cocoa" ] }, "archreq": 0, "className": "QCocoaIntegrationPlugin", "debug": false, "version": 331520 } Got keys from plugin meta data ("cocoa") QFactoryLoader::QFactoryLoader() checking directory path "/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/MacOS/platforms" ... Cannot load library /Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib: (dlopen(/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib, 0x0085): Library not loaded: @rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport Referenced from: <D4AB240B-4535-3AEC-B72B-5FFC4750E4E5> /Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib Reason: tried: '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtCore.framework/Versions/5/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/System/Volumes/Preboot/Cryptexes/OS@rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtCore.framework/Versions/5/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/System/Library/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file, not in dyld cache)) QLibraryPrivate::loadPlugin failed on "/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib" : "Cannot load library /Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib: (dlopen(/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib, 0x0085): Library not loaded: @rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport\n Referenced from: <D4AB240B-4535-3AEC-B72B-5FFC4750E4E5> /Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/libqcocoa.dylib\n Reason: tried: '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtCore.framework/Versions/5/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/System/Volumes/Preboot/Cryptexes/OS@rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/PlugIns/platforms/../../lib/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/Users/username/Desktop/MyApp/myapp/installers/macos/MyApp.app/Contents/Frameworks/QtCore.framework/Versions/5/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file), '/System/Library/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport' (no such file, not in dyld cache))" qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: cocoa. zsh: abort ./MyApp
Main error:
qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
These are the things I have tried, without success:
- Reinstall Qt completely
- Build the project from scratch
Finally, here are some details of the project configuration:
- It is developed in Qt, C++ and built using cmake.
- I don't use Python
- I need to build the project to run on MacOS.
- Qt Version: 5.15.2
- The application runs perfectly if I run it from Qt Creator.
Thanks in advance :)
@Alexuds79
Use dtruss to run your app to check which plugin is loaded or not found. It is likely a path issue.What is strace equivalent on Mac?
dtruss uses dtrace to lists process' syscall details. Comes handy every now and again. Check dtruss(1m) for details. -
@Alexuds79
Use dtruss to run your app to check which plugin is loaded or not found. It is likely a path issue.What is strace equivalent on Mac?
dtruss uses dtrace to lists process' syscall details. Comes handy every now and again. Check dtruss(1m) for details.@JoeCFD I can't do that since System Integrity Protection (SIP) is enabled by default on MacOS and it prevents most uses of dtrace and other tools and scripts based on it (i.e. dtruss).
From what I've read, there are ways to be able to use such commands, but they require booting into recovery mode, which could lead to other problems because I guess it requires modifying other settings on the computer.
-
@JoeCFD I can't do that since System Integrity Protection (SIP) is enabled by default on MacOS and it prevents most uses of dtrace and other tools and scripts based on it (i.e. dtruss).
From what I've read, there are ways to be able to use such commands, but they require booting into recovery mode, which could lead to other problems because I guess it requires modifying other settings on the computer.
@Alexuds79 said in My application crashes when trying to run the final .app of my project once built on MacOS: "Could not load the Qt platform plugin "cocoa" in "" even though it was found." How can I solve it?:
System Integrity Protection (SIP) is enabled by default on MacOS
disconnect your mac from network. Disable SIP temporarily and reenable it later. I guess you are safe.
https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection -
Hi,
How did you install Qt ?
Which version exactly ?
Did you already deploy your application ?
You seem to be missing the Print Support library based on the error message. -
In order to be able to execute the .app folder directly you need to use macdeploy. It will include the necessary Qt dynamic libraries inside the folder and adjust the search path for dynamic libraries. Only then do you get a proper Mac application. QtCreator works because it will launch the executable within the app folder directly and has the Qt paths set up properly.
-
Hello, first of all, thank you for your support! :)
Indeed, I build the final executable using macdeployqt. And after generating that final .app, I manually build the .pkg for installation. I have built this project several times in the same way and it has always worked fine, until now. The strange thing is that I haven't added any new libraries either.
For now, I'm trying to port the project from Qt 5.15 to Qt 6.4, in order to see if that solves the problem. It will take me a while, but I'll let you know if this fixes it or not.
Best regards!
-