[qt.qpa.plugin] Could not find the Qt platform plugin "cocoa" in ""
-
i'm trying to write my 1st qt program:
// https://wiki.qt.io/Qt_for_Beginners
#include <QApplication>
int main(int argc, char **argv, char **envp)
{for (char **env = envp; *env != 0; env++)
{
char *thisEnv = *env;
printf("%s\n", thisEnv);
}QApplication app (argc, argv);
return app.exec();
}—————————————————————————————
i created the xcode project with cmake:
cmake_minimum_required(VERSION 3.0)
project( 01_minimal )
set (CMAKE_CXX_STANDARD 11)
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)
add_executable( 01_minimal main.cpp )
target_link_libraries(01_minimal Qt5::Widgets)—————————————————————————————
i used brew to install qt:
MacBookPro2018:1-minimal$ brew info qt
qt: stable 5.12.2 (bottled), HEAD [keg-only]
Cross-platform application and UI framework
https://www.qt.io/
/usr/local/homebrew/Cellar/qt/5.12.0 (9,689 files, 318.9MB)
Poured from bottle on 2019-02-06 at 10:17:14
/usr/local/homebrew/Cellar/qt/5.12.2 (9,661 files, 313MB)
Poured from bottle on 2019-03-21 at 14:22:49
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/qt.rb
==> Dependencies
Build: pkg-config ✔
==> Requirements
Build: xcode ✔
Required: macOS >= 10.12 ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
We agreed to the Qt open source license for you.
If this is unacceptable you should uninstall.qt is keg-only, which means it was not symlinked into /usr/local/homebrew,
because Qt 5 has CMake issues when linked.If you need to have qt first in your PATH run:
echo 'export PATH="/usr/local/homebrew/opt/qt/bin:$PATH"' >> ~/.bash_profileFor compilers to find qt you may need to set:
export LDFLAGS="-L/usr/local/homebrew/opt/qt/lib"
export CPPFLAGS="-I/usr/local/homebrew/opt/qt/include"For pkg-config to find qt you may need to set:
export PKG_CONFIG_PATH="/usr/local/homebrew/opt/qt/lib/pkgconfig"==> Analytics
install: 70,091 (30 days), 158,029 (90 days), 449,532 (365 days)
install_on_request: 18,424 (30 days), 49,002 (90 days), 180,981 (365 days)
build_error: 0 (30 days)—————————————————————————————
xcode compiles it ok, but when i run it with either Xcode or from a script, i get an error, here is the script:
#!/bin/bash
export LD_LIBRARY_PATH=/usr/local/homebrew/opt/qt/lib:/usr/local/homebrew/Cellar/qt/5.12.2/plugins/platforms/:${LD_LIBRARY_PATH}
export DYLD_LIBRARY_PATH=/usr/local/homebrew/opt/qt/lib:/usr/local/homebrew/Cellar/qt/5.12.2/plugins/platforms/:${DYLD_LIBRARY_PATH}:
./Xcode/Debug/01_minimal—————————————————————————————
here is the Xcode execution (with an edited environment list):
LD_LIBRARY_PATH=/usr/local/homebrew/opt/qt/lib
PATH=/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
PKG_CONFIG_PATH=/usr/local/homebrew/opt/qt/lib/pkgconfig
DYLD_LIBRARY_PATH=/usr/local/homebrew/opt/qt/lib:/Users/xxx/Documents/C++/Qt/QtForBeginners/1-minimal/Xcode/Debug:/usr/lib/system/introspection
DYLD_FRAMEWORK_PATH=/Users/xxx/Documents/C++/Qt/QtForBeginners/1-minimal/Xcode/Debug2019-03-22 11:28:14.080647-0700 01_minimal[7469:130177] [qt.qpa.plugin] Could not find the Qt platform plugin "cocoa" in ""
—————————————————————————————
i notice others had this problem & they were routinely asked to use otool:
$ otool -L Xcode/Debug/01_minimal
Xcode/Debug/01_minimal:
/usr/local/homebrew/opt/qt/lib/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.12.0, current version 5.12.2)
/usr/local/homebrew/opt/qt/lib/QtGui.framework/Versions/5/QtGui (compatibility version 5.12.0, current version 5.12.2)
/usr/local/homebrew/opt/qt/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.12.0, current version 5.12.2)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)and, sure enough, i am missing anything with the name cocoa
—————————————————————————————
i found libqcocoa.dylib:
$ ls -al /usr/local/homebrew/Cellar/qt/5.12.2/plugins/platforms
total 9944
drwxr-xr-x 6 xxx staff 192 Mar 11 07:24 .
drwxr-xr-x 29 xxx staff 928 Mar 11 07:24 ..
-rwxr-xr-x 1 xxx staff 1744876 Mar 21 14:22 libqcocoa.dylib
-rwxr-xr-x 1 xxx staff 962164 Mar 21 14:22 libqminimal.dylib
-rwxr-xr-x 1 xxx staff 980512 Mar 21 14:22 libqoffscreen.dylib
-rwxr-xr-x 1 xxx staff 1400264 Mar 21 14:22 libqwebgl.dylibso i added the directory to LD_LIBRARY_PATH & DYLD_LIBRARY_PATH:
DYLD_LIBRARY_PATH=/usr/local/homebrew/opt/qt/lib:/usr/local/homebrew/Cellar/qt/5.12.2/plugins/platforms:/Users/xxx/Documents/C++/Qt/QtForBeginners/1-minimal/Xcode/Debug:/usr/lib/system/introspection
LD_LIBRARY_PATH=/usr/local/homebrew/opt/qt/lib:/usr/local/homebrew/Cellar/qt/5.12.2/plugins/platforms
this didn’t help