macOS Monterey 12.4, Xcode 13.4.1, Qt 6.4.2 built as static universal binary. Runtime error: Could not find the Qt platform plugin "cocoa" in ""
-
Hi,
Summary
Running a very simple test program linked against Qt 6.4.2 static libraries encounters a runtime error.
Description
I work with Xcode 13.4.1 project on macOS Monterey v 12.4. I built and added Qt 6.4.2 to this Xcode project as universal binary static libraries. After built this Xcode project successfully I run the app binary and got some messages:
2023-04-20 17:17:18.664487+0300 TestApp[88499:18870480] [qt.qpa.plugin] Could not find the Qt platform plugin "cocoa" in ""
2023-04-20 17:17:18.664943+0300 TestApp[88499:18870480] This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Program ended with exit code: 9
Request
I would like help if the problems are related to my configuration, otherwise please fix the problem of adding the Qt framework plugin "cocoa".Narrative
I tried to add Qt 6.4.2 built as static libraries to my Xcode project for MacOS, but I can't do that.
I use macOS Monterey v 12.4, Mac mini (M1,2020), Memory 16 GB
I use Qt for macOS - Building from Source article (ref https://doc.qt.io/qt-6/macos-building.html)
to configure, build, install and deploy Qt 6.4.2.-
I cloned qt repository using
$ git clone git://code.qt.io/qt/qt5.git qt6 -
Checked and installed following applications:
2.1. Xcode 13.4.1
2.1. CMake version 3.26.
2.2. Ninja 1.11.1.
2.3. Perl 5.30.3
2.4. Python 2.7. -
Switched on qt 6.4.2 version
git checkout --track origin/6.4.2 -
Move directory and files from qt6 directory to Src directory
-
cd Src.
/Users/test/qt/6.4.2/Src -
Initialize repository
perl init-repository -
Configure qt sources before build. The Qt 6.4.2
I configure qt 6.4.2 as universal binary static libraries
7.1. For Debug configuration I use following (Installation path: /Users/test/qt/6.4.2/build-universal-binary/debug):
cmake . '-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64' '-DBUILD_schannel=OFF' '-DBUILD_qtactiveqt=OFF' '-DBUILD_qtcoap=OFF' '-DBUILD_qtconnectivity=OFF' '-DBUILD_qtlocation=OFF' '-DBUILD_qtlottie=OFF' '-DBUILD_qtmqtt=OFF' '-DBUILD_qtmultimedia=OFF' '-DBUILD_qtopcua=OFF' '-DBUILD_qtscxml=OFF' '-DBUILD_qtsensors=OFF' '-DBUILD_qtserialbus=OFF' '-DBUILD_qtserialport=OFF' '-DBUILD_qtvirtualkeyboard=OFF' '-DBUILD_qtwayland=OFF' '-DBUILD_qtwebchannel=OFF' '-DBUILD_qtwebengine=OFF' '-DBUILD_qtwebsockets=OFF' '-DBUILD_qtwebview=OFF' '-DBUILD_qtquick3dphysics=OFF' '-DBUILD_qtquick3d=OFF' '-DBUILD_SHARED_LIBS=OFF' '-DCMAKE_INSTALL_PREFIX=/Users/test/qt/6.4.2/build-universal-binary/debug' '-DCMAKE_BUILD_TYPE=Debug' '-DINPUT_cxx14=yes' '-DINPUT_cxx17=yes' '-DINPUT_cxx20=no' '-DINPUT_gui=yes' '-DINPUT_widgets=yes' '-DINPUT_framework=no' '-DINPUT_system_zlib=no' '-DINPUT_dbus=no' '-G' 'Ninja' '/Users/test/qt/6.4.2/Src'
7.2. For Release configuration I use following (Installation path: /Users/test/qt/6.4.2/build-universal-binary/release):
cmake . '-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64' '-DBUILD_schannel=OFF' '-DBUILD_qtactiveqt=OFF' '-DBUILD_qtcoap=OFF' '-DBUILD_qtconnectivity=OFF' '-DBUILD_qtlocation=OFF' '-DBUILD_qtlottie=OFF' '-DBUILD_qtmqtt=OFF' '-DBUILD_qtmultimedia=OFF' '-DBUILD_qtopcua=OFF' '-DBUILD_qtscxml=OFF' '-DBUILD_qtsensors=OFF' '-DBUILD_qtserialbus=OFF' '-DBUILD_qtserialport=OFF' '-DBUILD_qtvirtualkeyboard=OFF' '-DBUILD_qtwayland=OFF' '-DBUILD_qtwebchannel=OFF' '-DBUILD_qtwebengine=OFF' '-DBUILD_qtwebsockets=OFF' '-DBUILD_qtwebview=OFF' '-DBUILD_qtquick3dphysics=OFF' '-DBUILD_qtquick3d=OFF' '-DBUILD_SHARED_LIBS=OFF' '-DCMAKE_INSTALL_PREFIX=/Users/test/qt/6.4.2/build-universal-binary/release' '-DCMAKE_BUILD_TYPE=Release' '-DINPUT_cxx14=yes' '-DINPUT_cxx17=yes' '-DINPUT_cxx20=no' '-DINPUT_gui=yes' '-DINPUT_widgets=yes' '-DINPUT_framework=no' '-DINPUT_system_zlib=no' '-DINPUT_dbus=no' '-G' 'Ninja' '/Users/test/qt/6.4.2/Src' -
Build
cmake --build . --parallel -
Install
cmake --install . -
Added to environment variable PATH a path of qt 6.4.2 bin directory(/Users/test/qt/6.4.2/build-universal-binary/release/bin) to .zprofile
-
I create c++ project as App template, target and scheme in Xcode.
11.1. To the project target build settings were added:
11.1.1. System header search paths
11.1.1.1. to Debug configuration:
SYSTEM_HEADER_SEARCH_PATHS=/Users/test/qt/6.4.2/build-universal-binary/debug/include
11.1.1.2. to Release configuration:
SYSTEM_HEADER_SEARCH_PATHS=/Users/test/qt/6.4.2/build-universal-binary/release/include
11.1.2. Library search paths
11.1.2.1. to Debug configuration:
LIBRARY_SEARCH_PATHS=/Users/test/qt/6.4.2/build-universal-binary/debug/lib /Users/test/qt/6.4.2/build-universal-binary/debug/plugins /Users/test/qt/6.4.2/build-universal-binary/debug/plugins/platforms
11.1.2.2. to Release configuration:
LIBRARY_SEARCH_PATHS=/Users/test/qt/6.4.2/build-universal-binary/release/lib /Users/test/qt/6.4.2/build-universal-binary/release/plugins /Users/test/qt/6.4.2/build-universal-binary/release/plugins/platforms
11.2. To the project target build phases -> Link Binary With Libraries were added following static libraries:
11.2.1. to Debug configuration:
-libQt6BoundledFreetype_debug.a
-libQt6BoundledHarfbuzz_debug.a
-libQt6BoundledLibpng_debug.a
-libQt6BoundledPcre2_debug.a
-libQt6BoundledZLIB_debug.a
-libQt6Core_debug.a
-libQt6Core5Compat_debug.a
-libQt6Gui_debug.a
-libQt6Widgets_debug.a
for platforms plugins
-liqcocoa_debug.a
-libqminimal_debug.a
-libqoffscreen_debug.a
11.2.2. to Release configuration:
-libQt6BoundledFreetype.a
-libQt6BoundledHarfbuzz.a
-libQt6BoundledLibpng.a
-libQt6BoundledPcre2.a
-libQt6BoundledZLIB.a
-libQt6Core.a
-libQt6Core5Compat.a
-libQt6Gui.a
-libQt6Widgets.a
for platforms plugins:
-liqcocoa.a
-libqminimal.a
-libqoffscreen.a
Also I added following frameworks:
-Metal.framework
-IOKit.framework
-Security.framework
-Cocoa.framework
-CoreFundation.framework
11.3. I have one module main.cpp
Its content looks like below:
=====================
#include <QtWidgets/QApplication>
int main(int argc, const char * argv[]) {
QApplication a(argc, const_cast<char **>(argv));
return a.exec();
} -
Results
12.1. I built the project scheme with the target successfully but when my app binary run I got some messages:
2023-04-20 17:17:18.664487+0300 TestApp[88499:18870480] [qt.qpa.plugin] Could not find the Qt platform plugin "cocoa" in ""
2023-04-20 17:17:18.664943+0300 TestApp[88499:18870480] This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Program ended with exit code: 9
===============
The problem is in method QGuiApplicationPrivate::EventDispatcher()
when it calls QGuiAplicationPrivate::createPlatformIntegration().
As a result it is got qt_message_fatal and after that a call qAbort()
[qt.qpa.plugin] Could not find the Qt platform plugin "cocoa" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
12.2. I tried to fix the issue. I added to application scheme environment variables with paths to statically built qt platforms plugins
12.2.1. to Debug configuration
QT_QPA_PLATFORM_PLUGIN_PATH=/Users/test/qt/6.4.2/build-universal-binary/Debug/plugins/platforms
QT_PUGIN_PATH=/Users/test/qt/6.4.2/build-universal-binary/Debug/plugins/
QT_DEBUG_PLUGINS=1
I've got messages:
2023-04-20 18:57:42.559536+0300 TestApp[89236:18923856] [qt.core.plugin.factoryloader] ignoring "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3" since plugins are disabled in static builds
2023-04-20 18:57:42.559736+0300 TestApp[89236:18923856] [qt.core.plugin.factoryloader] checking directory path "/Users/test/qt/6.4.2/build-universal-binary/Debug/plugins/platforms" ...
2023-04-20 18:57:42.568289+0300 TestApp[89236:18923856] [qt.qpa.plugin] Could not find the Qt platform plugin "cocoa" in "/Users/test/qt/6.4.2/build-universal-binary/Debug/plugins/platforms"
2023-04-20 18:57:42.568455+0300 TestApp[89236:18923856] This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Program ended with exit code: 9
12.2.1. to Release configuration
QT_QPA_PLATFORM_PLUGIN_PATH=/Users/avid/qt/6.4.2/build-universal-binary/Release/plugins/platforms
QT_PUGIN_PATH=/Users/avid/qt/6.4.2/build-universal-binary/Release/plugins/
QT_DEBUG_PLUGINS=1
2023-04-20 18:57:42.559536+0300 TestApp[89236:18923856] [qt.core.plugin.factoryloader] ignoring "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3" since plugins are disabled in static builds
2023-04-20 18:57:42.559736+0300 TestApp[89236:18923856] [qt.core.plugin.factoryloader] checking directory path "/Users/test/qt/6.4.2/build-universal-binary/Release/plugins/platforms" ...
2023-04-20 18:57:42.568289+0300 TestApp[89236:18923856] [qt.qpa.plugin] Could not find the Qt platform plugin "cocoa" in "/Users/test/qt/6.4.2/build-universal-binary/Release/plugins/platforms"
2023-04-20 18:57:42.568455+0300 TestApp[89236:18923856] This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Program ended with exit code: 9
I added otool -L TestApp output
otool -L TestApp
TestApp:
/System/Library/Frameworks/Metal.framework/Versions/A/Metal (compatibility version 1.0.0, current version 261.13.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 60158.100.133)
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 23.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1858.112.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.23.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2113.40.126)
/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1557.5.4)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1141.1.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1858.112.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
12.3 As a result, I would like help if the problems were related to my configuration, otherwise please fix the problem of adding the Qt framework plugin "cocoa".
-
-
Before creating QApplication, QWindow objects, it's needed to add platform-specific QPA (Qt Platform Abstraction) Plugin support. In order to add it, it's needed to pass the PluginClassName as a parameter of the Q_IMPORT_PLUGIN macro
Q_IMPORT_PLUGIN(PluginClassName );
The PluginClassName can be taken from the table below
https://doc.qt.io/qt-6/qpa.htmlIn that case (Could not find the Qt platform plugin "cocoa" in "") before creation QApplication object it's needed to add macro Q_IMPORT_PLUGIN with QCocoaIntegrationPlugin parameter:
Q_IMPORT_PLUGIN (QCocoaIntegrationPlugin);
It works fine! -
S SGaist has marked this topic as solved on