Project

General

Profile

Emulator Issues #11332

Build MacOSX Could not load the Qt platform plugin "cocoa" in "" even though it was found.

Added by firodj about 2 years ago. Updated over 1 year ago.

Status:
New
Priority:
Normal
Assignee:
-
% Done:

0%

Operating system:
OS X
Issue type:
Bug
Milestone:
Regression:
No
Relates to usability:
No
Relates to performance:
No
Easy:
No
Relates to maintainability:
No
Regression start:
Fixed in:

Description

Got error after successful build using CMake on Mac OSX High Sierra. Qt5 was installed using Qt Online Installer for macOS.

The error message when running Dolphin:

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.

After inspecting with otool the problem was the @rpath (LC_RPATH) which not set on the Dolphin executable (target dolphin-emu) which needed by libqcocoa.dylib.

otool -L Binaries/Dolphin.app/Contents/MacOS/platforms/libqcocoa.dylib 
Binaries/Dolphin.app/Contents/MacOS/platforms/libqcocoa.dylib:
    libqcocoa.dylib (compatibility version 0.0.0, current version 0.0.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1504.82.104)
    /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)
    /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
    /usr/lib/libcups.2.dylib (compatibility version 2.0.0, current version 2.12.0)
    @rpath/QtGui.framework/Versions/5/QtGui (compatibility version 5.11.0, current version 5.11.1)
    @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.11.0, current version 5.11.1)
    /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)
    /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1349.64.0)
    /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1070.22.0)
    /System/Library/Frameworks/CoreText.framework/Versions/A/CoreText (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1349.63.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8)
    /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO (compatibility version 1.0.0, current version 1.0.0)
    @rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport (compatibility version 5.11.0, current version 5.11.1)
    @rpath/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.11.0, current version 5.11.1)
    /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)
    /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 48.0.0)
    /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 775.19.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

to solve this use install_name_tool.

diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt
index eff3bdd840..cdf7ca1651 100644
--- a/Source/Core/DolphinQt/CMakeLists.txt
+++ b/Source/Core/DolphinQt/CMakeLists.txt
@@ -227,3 +227,9 @@ endif()
 if(USE_DISCORD_PRESENCE)
   target_compile_definitions(dolphin-emu PRIVATE -DUSE_DISCORD_PRESENCE)
 endif()
+
+# Fix rpath
+add_custom_command(TARGET dolphin-emu 
+  POST_BUILD COMMAND 
+  ${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path/../Frameworks/"
+  $<TARGET_FILE:dolphin-emu>)
\ No newline at end of file

After fixing:

otool -l Binaries/Dolphin.app/Contents/MacOS/Dolphin  | grep LC_RPATH -A 4
          cmd LC_RPATH
      cmdsize 48
         path @executable_path/../Frameworks/ (offset 12)

History

#1 Updated by kvark over 1 year ago

I faced the same issue on a fresh system, although with more output:

objc[21251]: Class QMacAutoReleasePoolTracker is implemented in both /Users/mozilla/Code/dolphin/build/Binaries/Dolphin.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore (0x10f600080) and /usr/local/Cellar/qt/5.12.2/lib/QtCore.framework/Versions/5/QtCore (0x113672080). One of the two will be used. Which one is undefined.
objc[21251]: Class QT_ROOT_LEVEL_POOL__THESE_OBJECTS_WILL_BE_RELEASED_WHEN_QAPP_GOES_OUT_OF_SCOPE is implemented in both /Users/mozilla/Code/dolphin/build/Binaries/Dolphin.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore (0x10f6000f8) and /usr/local/Cellar/qt/5.12.2/lib/QtCore.framework/Versions/5/QtCore (0x1136720f8). One of the two will be used. Which one is undefined.
objc[21251]: Class RunLoopModeTracker is implemented in both /Users/mozilla/Code/dolphin/build/Binaries/Dolphin.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore (0x10f600120) and /usr/local/Cellar/qt/5.12.2/lib/QtCore.framework/Versions/5/QtCore (0x113672120). One of the two will be used. Which one is undefined.
QObject::moveToThread: Current thread (0x7fc582f00080) is not the object's thread (0x7fc582f07df0).
Cannot move to target thread (0x7fc582f00080)

You might be loading two sets of Qt binaries into the same process. Check that all plugins are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
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.

Applying the proposed fix to CMakeLists txt and re-building doesn't work for me:

Binaries/Dolphin.app/Contents/MacOS/platforms/libqcocoa.dylib:
    /usr/local/opt/qt/plugins/platforms/libqcocoa.dylib (compatibility version 0.0.0, current version 0.0.0)
    /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 934.0.0)
    /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 158.0.0)
    /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
    /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0)
    /System/Library/Frameworks/Metal.framework/Versions/A/Metal (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libcups.2.dylib (compatibility version 2.0.0, current version 2.13.0)
    /usr/local/Cellar/qt/5.12.2/lib/QtDBus.framework/Versions/5/QtDBus (compatibility version 5.12.0, current version 5.12.2)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1560.12.0)
    /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1247.4.1)
    /System/Library/Frameworks/CoreText.framework/Versions/A/CoreText (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1560.12.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.11)
    /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1671.10.106)
    /usr/local/Cellar/qt/5.12.2/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport (compatibility version 5.12.0, current version 5.12.2)
    /usr/local/Cellar/qt/5.12.2/lib/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.12.0, current version 5.12.2)
    /usr/local/Cellar/qt/5.12.2/lib/QtGui.framework/Versions/5/QtGui (compatibility version 5.12.0, current version 5.12.2)
    /usr/local/Cellar/qt/5.12.2/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.12.0, current version 5.12.2)
    /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)
    /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 400.9.4)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
    /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 50.1.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

Changes from master:

diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt
index 85bc526ae6..ae6b28336f 100644
--- a/Source/Core/DolphinQt/CMakeLists.txt
+++ b/Source/Core/DolphinQt/CMakeLists.txt
@@ -239,3 +239,9 @@ endif()
 if(USE_DISCORD_PRESENCE)
   target_compile_definitions(dolphin-emu PRIVATE -DUSE_DISCORD_PRESENCE)
 endif()
+
+# Fix rpath
+add_custom_command(TARGET dolphin-emu
+  POST_BUILD COMMAND
+  ${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path/../Frameworks/"
+  $<TARGET_FILE:dolphin-emu>)

Might have something to do that I provided Qt5_DIR=/usr/local/Cellar/qt/5.12.2 upon running CMake? It doesn't find Qt otherwise.
Please let me know if this is a different issue that should be filed separately.

#2 Updated by kvark over 1 year ago

Found a hack that solves this for me:

diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt
index 86a73c34ed..9fc1599fdd 100644
--- a/Source/Core/DolphinQt/CMakeLists.txt
+++ b/Source/Core/DolphinQt/CMakeLists.txt
@@ -220,8 +220,8 @@ if(APPLE)
   endforeach()

   # Update library references to make the bundle portable
-  include(DolphinPostprocessBundle)
-  dolphin_postprocess_bundle(dolphin-emu)
+  #include(DolphinPostprocessBundle) #TODO
+  #dolphin_postprocess_bundle(dolphin-emu)
 else()
   install(TARGETS dolphin-emu RUNTIME DESTINATION ${bindir})
 endif()

#3 Updated by spycrab0 over 1 year ago

  • Operating system OS X added
  • Operating system deleted (N/A)

I can't reproduce this with a very similar setup (only the Qt version is newer IIRC).
Could you try to bisect the issue?

#4 Updated by firodj over 1 year ago

I've got same exact error message on macOS Mojave (10.14.3), and the solution is still the same.

When I read again my blog: https://firodj.wordpress.com/2018/08/09/qt5-mac-osx-build-dolphin/ maybe to place where the custom command to put has an effect and it is after dolphin_postprocess_bundle(dolphin-emu).

My setup for env on ~/.bash_profile:

export Qt5_DIR=/usr/local/opt/qt5
export PATH=$PATH:$Qt5_DIR/bin

Then just rebuild with cmake --build .
Could you make sure if the LC_RPATH take effect? with otool -l (small letter l), see my blog.
I am using cmake version 3.14.3 and qt 5.12.2 from Homebrew.

kvark wrote:

I faced the same issue on a fresh system, although with more output:

objc[21251]: Class QMacAutoReleasePoolTracker is implemented in both /Users/mozilla/Code/dolphin/build/Binaries/Dolphin.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore (0x10f600080) and /usr/local/Cellar/qt/5.12.2/lib/QtCore.framework/Versions/5/QtCore (0x113672080). One of the two will be used. Which one is undefined.
objc[21251]: Class QT_ROOT_LEVEL_POOL__THESE_OBJECTS_WILL_BE_RELEASED_WHEN_QAPP_GOES_OUT_OF_SCOPE is implemented in both /Users/mozilla/Code/dolphin/build/Binaries/Dolphin.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore (0x10f6000f8) and /usr/local/Cellar/qt/5.12.2/lib/QtCore.framework/Versions/5/QtCore (0x1136720f8). One of the two will be used. Which one is undefined.
objc[21251]: Class RunLoopModeTracker is implemented in both /Users/mozilla/Code/dolphin/build/Binaries/Dolphin.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore (0x10f600120) and /usr/local/Cellar/qt/5.12.2/lib/QtCore.framework/Versions/5/QtCore (0x113672120). One of the two will be used. Which one is undefined.
QObject::moveToThread: Current thread (0x7fc582f00080) is not the object's thread (0x7fc582f07df0).
Cannot move to target thread (0x7fc582f00080)

You might be loading two sets of Qt binaries into the same process. Check that all plugins are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
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.

Also available in: Atom PDF