Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. 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?

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?

Scheduled Pinned Locked Moved Solved Installation and Deployment
8 Posts 4 Posters 570 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alexuds79
    wrote on last edited by Alexuds79
    #1

    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 :)

    JoeCFDJ 1 Reply Last reply
    0
    • A Offline
      A Offline
      Alexuds79
      wrote on last edited by
      #8

      The migration to Qt6.4 seems to have solved the problem. Thank you all.

      1 Reply Last reply
      0
      • A Alexuds79

        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 :)

        JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #2

        @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.

        A 1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          @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.

          A Offline
          A Offline
          Alexuds79
          wrote on last edited by
          #3

          @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.

          JoeCFDJ 1 Reply Last reply
          0
          • A Alexuds79

            @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.

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #4

            @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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SimonSchroeder
                wrote on last edited by
                #6

                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.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Alexuds79
                  wrote on last edited by
                  #7

                  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!

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Alexuds79
                    wrote on last edited by
                    #8

                    The migration to Qt6.4 seems to have solved the problem. Thank you all.

                    1 Reply Last reply
                    0
                    • A Alexuds79 has marked this topic as solved on

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved