Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating .dmg for Qt app mac OSX
Forum Updated to NodeBB v4.3 + New Features

Creating .dmg for Qt app mac OSX

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 4 Posters 11.4k Views 1 Watching
  • 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.
  • R Rondog

    I think I know how to fix your problem (or pretty sure at least).

    What is happening is macdeployqt is looking at the path and thinks it is a system file so it is not added to your application (app). I believe the libz.1.dylib is part of zlib and you happen to have it installed in /usr/lib/. I am not sure how it was linked to your plugins but this is less important (but could be the other solution - remove this dependency from your plugins).

    You will need to modify the source of macdeployqt to fix your problem. From the Qt sources you will find the macdeployqt program and file of interest here: qt-everywhere-opensource-src-5.x.x/qttools/src/macdeployqt/shared/shared.cpp You need to add an exception to allow /usr/lib/libz.1.dylib

    The function 'parseOtoolLibraryLine(...)' checks the path and (very correctly) doesn't include anything that is likely a system file. In your case /usr/lib/libz.1.dylib is thought to be a system library so it is not included. I am using Qt 5.6.0 and I know you have 5.10.x so there may be some differences in what I posted for source but i suspect they are small.

    I actually ran into this problem as well. I compiled Qt from sources and installed it in /usr/lib/qt5 using the -prefix option. I know this is not the right place on OSX but it is a location I have used on GNU/Linux and simply stuck with it. I added an exception to the above mentioned file (and function) so that anything starting with /usr/lib/qt5 was not rejected.

    FrameworkInfo parseOtoolLibraryLine(const QString &line, const QString &appBundlePath, const QSet<QString> &rpaths, bool useDebugLibs)
    {
        FrameworkInfo info;
        QString trimmed = line.trimmed();
    
        if (trimmed.isEmpty())
            return info;
    
        // Don't deploy system libraries.
        if (trimmed.startsWith("/System/Library/") ||
            (trimmed.startsWith("/usr/lib/") && trimmed.contains("libQt") == false) // exception for libQtuitools and libQtlucene
            || trimmed.startsWith("@executable_path") || trimmed.startsWith("@loader_path"))
            return info;
    ...
    
    
    A Offline
    A Offline
    Arqam
    wrote on last edited by
    #13
    This post is deleted!
    1 Reply Last reply
    0
    • R Rondog

      I think I know how to fix your problem (or pretty sure at least).

      What is happening is macdeployqt is looking at the path and thinks it is a system file so it is not added to your application (app). I believe the libz.1.dylib is part of zlib and you happen to have it installed in /usr/lib/. I am not sure how it was linked to your plugins but this is less important (but could be the other solution - remove this dependency from your plugins).

      You will need to modify the source of macdeployqt to fix your problem. From the Qt sources you will find the macdeployqt program and file of interest here: qt-everywhere-opensource-src-5.x.x/qttools/src/macdeployqt/shared/shared.cpp You need to add an exception to allow /usr/lib/libz.1.dylib

      The function 'parseOtoolLibraryLine(...)' checks the path and (very correctly) doesn't include anything that is likely a system file. In your case /usr/lib/libz.1.dylib is thought to be a system library so it is not included. I am using Qt 5.6.0 and I know you have 5.10.x so there may be some differences in what I posted for source but i suspect they are small.

      I actually ran into this problem as well. I compiled Qt from sources and installed it in /usr/lib/qt5 using the -prefix option. I know this is not the right place on OSX but it is a location I have used on GNU/Linux and simply stuck with it. I added an exception to the above mentioned file (and function) so that anything starting with /usr/lib/qt5 was not rejected.

      FrameworkInfo parseOtoolLibraryLine(const QString &line, const QString &appBundlePath, const QSet<QString> &rpaths, bool useDebugLibs)
      {
          FrameworkInfo info;
          QString trimmed = line.trimmed();
      
          if (trimmed.isEmpty())
              return info;
      
          // Don't deploy system libraries.
          if (trimmed.startsWith("/System/Library/") ||
              (trimmed.startsWith("/usr/lib/") && trimmed.contains("libQt") == false) // exception for libQtuitools and libQtlucene
              || trimmed.startsWith("@executable_path") || trimmed.startsWith("@loader_path"))
              return info;
      ...
      
      
      A Offline
      A Offline
      Arqam
      wrote on last edited by Arqam
      #14

      @Rondog said in Creating .dmg for Qt app mac OSX:

      5.10.x

      I edited the shared.cpp file.

      The error that I get now is the following:

      QFactoryLoader::QFactoryLoader() checking directory path "/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms" ...
      QFactoryLoader::QFactoryLoader() looking at "/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib"
      Found metadata in lib /Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib, metadata=
      {
          "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
          "MetaData": {
              "Keys": [
                  "cocoa"
              ]
          },
          "className": "QCocoaIntegrationPlugin",
          "debug": false,
          "version": 329218
      }
      
      
      Got keys from plugin meta data ("cocoa")
      QFactoryLoader::QFactoryLoader() checking directory path "/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/MacOS/platforms" ...
      Cannot load library /Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib: (dlopen(/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib, 133): Library not loaded: @rpath/libQt5PrintSupport.5.dylib
        Referenced from: /Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib
        Reason: image not found)
      QLibraryPrivate::loadPlugin failed on "/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib" : "Cannot load library /Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib: (dlopen(/Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib, 133): Library not loaded: @rpath/libQt5PrintSupport.5.dylib\n  Referenced from: /Users/arqam/Desktop/Junk/build-QTDMGProj-Desktop_Qt_5_10_0_clang_64bit-Release/QTDMGProj.app/Contents/PlugIns/platforms/libqcocoa.dylib\n  Reason: image not found)"
      This application failed to start because it could not find or load the Qt platform plugin "cocoa"
      in "".
      
      Available platform plugins are: cocoa.
      
      Reinstalling the application may fix this problem.
      Abort trap: 6
      

      I tried with both the lines in my .pro file :

      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
      

      as well as without printsupport but it gives the same error of Library not loaded: @rpath/libQt5PrintSupport.5.dylib

      Is it because of anything that I did? When I run otool -L libcocoa.dylib I get the following :

      libqcocoa.dylib:
      	@rpath/../plugins/platforms/libqcocoa.dylib (compatibility version 0.0.0, current version 0.0.0)
      	/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 21.0.0)
      	/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)
      	/usr/lib/libcups.2.dylib (compatibility version 2.0.0, current version 2.11.0)
      	/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)
      	@rpath/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8)
      	/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 48.0.0)
      	/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1343.14.0)
      	/System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
      	@rpath/libQt5PrintSupport.5.dylib (compatibility version 5.6.0, current version 5.6.2)
      	@rpath/libQt5Widgets.5.dylib (compatibility version 5.6.0, current version 5.6.2)
      	@rpath/libQt5Gui.5.dylib (compatibility version 5.6.0, current version 5.6.2)
      	@rpath/libQt5Core.5.dylib (compatibility version 5.6.0, current version 5.6.2)
      	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
      	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
      	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1151.16.0)
      	/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 62.0.0)
      	/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1151.16.0)
      	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
      

      In the Framework folder I have these three only :
      QtCore.framework QtGui.framework QtWidgets.framework
      And what it is searching for is @rpath/libQt5PrintSupport.5.dylib and the library that I have in path : /Contents/PlugIns/printsupport is libcocoaprintersupport.dylib

      @Rondog Please mail me : So that I can reply as soon as you post. Email : arq.ahmad.arqam@gmail.com

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rondog
        wrote on last edited by Rondog
        #15

        I am not sure if I was clear about modifying the utility macdeployqt. After you change this program you need to compile it and make sure you are actually using the new version when it is used.

        To add an exception for the libz.1.dylib the function parseOtoolLibraryLine(...) might end up looking like this:

        FrameworkInfo parseOtoolLibraryLine(const QString &line, const QString &appBundlePath, const QSet<QString> &rpaths, bool useDebugLibs)
        {
            FrameworkInfo info;
            QString trimmed = line.trimmed();
        
            if (trimmed.isEmpty())
                return info;
        
            if(trimmed.startsWith("/usr/lib/libz.1.dylib") == false) // specifically allow this file.
            {
        		// Don't deploy system libraries.
        		if (trimmed.startsWith("/System/Library/") ||
        			(trimmed.startsWith("/usr/lib/") && trimmed.contains("libQt") == false) // exception for libQtuitools and libQtlucene
        			|| trimmed.startsWith("@executable_path") || trimmed.startsWith("@loader_path"))
        			return info;
            }
        ...
        

        After changing this file you need to compile it. From the directory of macdeployqt (i.e. qt-everywhere-opensource-src-5.x.x/qttools/src/macdeployqt) you need to compile from the terminal:

        cd ~/<wherever you have the qt sources>/qttools/src/macdeployqt
        make
        

        If you only have the sources and a precompiled version of Qt you probably need to do something like this to create the make files:

        cd ~/<wherever you have the qt sources>/qttools/src/macdeployqt
        qmake
        make
        

        You need to make sure that you are actually using the new compiled version when you run this program. You need to copy the new version to the location where you currently have the binary macdeployqt application or specify the full path to the executable when running it.

        The end result of all this is that you should see the libz.1.dylib library somewhere in your app bundle.

        The other item (libQt5PrintSupport.5.dylib) is something I did notice previously. One thing you could try is to copy the missing framework into the app (same layout as the other frameworks) and see if it makes a difference. I am not sure if the framework is adjusted like all the other executables (i.e. using @rpath/...) but it should be suitable as a test regardless if it is modified. It will tell you if you need to get this packaged with the rest of your app.

        Note: When you run macdeployqt you can ask it for more details about what it is doing by adding the switch -verbose

        -verbose=<0-3>     : 0 = no output, 1 = error/warning (default), 2 = normal, 3 = debug
        
        A 1 Reply Last reply
        3
        • R Rondog

          I am not sure if I was clear about modifying the utility macdeployqt. After you change this program you need to compile it and make sure you are actually using the new version when it is used.

          To add an exception for the libz.1.dylib the function parseOtoolLibraryLine(...) might end up looking like this:

          FrameworkInfo parseOtoolLibraryLine(const QString &line, const QString &appBundlePath, const QSet<QString> &rpaths, bool useDebugLibs)
          {
              FrameworkInfo info;
              QString trimmed = line.trimmed();
          
              if (trimmed.isEmpty())
                  return info;
          
              if(trimmed.startsWith("/usr/lib/libz.1.dylib") == false) // specifically allow this file.
              {
          		// Don't deploy system libraries.
          		if (trimmed.startsWith("/System/Library/") ||
          			(trimmed.startsWith("/usr/lib/") && trimmed.contains("libQt") == false) // exception for libQtuitools and libQtlucene
          			|| trimmed.startsWith("@executable_path") || trimmed.startsWith("@loader_path"))
          			return info;
              }
          ...
          

          After changing this file you need to compile it. From the directory of macdeployqt (i.e. qt-everywhere-opensource-src-5.x.x/qttools/src/macdeployqt) you need to compile from the terminal:

          cd ~/<wherever you have the qt sources>/qttools/src/macdeployqt
          make
          

          If you only have the sources and a precompiled version of Qt you probably need to do something like this to create the make files:

          cd ~/<wherever you have the qt sources>/qttools/src/macdeployqt
          qmake
          make
          

          You need to make sure that you are actually using the new compiled version when you run this program. You need to copy the new version to the location where you currently have the binary macdeployqt application or specify the full path to the executable when running it.

          The end result of all this is that you should see the libz.1.dylib library somewhere in your app bundle.

          The other item (libQt5PrintSupport.5.dylib) is something I did notice previously. One thing you could try is to copy the missing framework into the app (same layout as the other frameworks) and see if it makes a difference. I am not sure if the framework is adjusted like all the other executables (i.e. using @rpath/...) but it should be suitable as a test regardless if it is modified. It will tell you if you need to get this packaged with the rest of your app.

          Note: When you run macdeployqt you can ask it for more details about what it is doing by adding the switch -verbose

          -verbose=<0-3>     : 0 = no output, 1 = error/warning (default), 2 = normal, 3 = debug
          
          A Offline
          A Offline
          Arqam
          wrote on last edited by Arqam
          #16

          @Rondog Right now I am using the QT installed using the installer. I have generated the Src using Maintenance tool.
          So when I make the QT src, will the QTCreator use the new library or the one that I got using QT installer already?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rondog
            wrote on last edited by
            #17

            @Arqam Somewhere on your computer you will have the binary version of macdeployqt that QtCreator is using (likely in the bin folder from wherever Qt is installed). After you compile the new version you need to make sure it ends up in the proper location. Just rename the old one and copy the new one in its place. You can do a search to find all copies of this binary just to be sure.

            I assume QtCreator is not using its own version of macdeployqt. I am also assuming that you are only compiling macdeployqt. If you are thinking of compiling all of Qt this is a bit more work. I don't think you need to compile all of Qt (at least I would hope not).

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

              Qt Creator uses the tools from the Qt version assigned to the Kit used to build the application.

              And no, there's no need to re-build all of Qt to build only one module.

              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
              1
              • R Rondog

                @Arqam Somewhere on your computer you will have the binary version of macdeployqt that QtCreator is using (likely in the bin folder from wherever Qt is installed). After you compile the new version you need to make sure it ends up in the proper location. Just rename the old one and copy the new one in its place. You can do a search to find all copies of this binary just to be sure.

                I assume QtCreator is not using its own version of macdeployqt. I am also assuming that you are only compiling macdeployqt. If you are thinking of compiling all of Qt this is a bit more work. I don't think you need to compile all of Qt (at least I would hope not).

                A Offline
                A Offline
                Arqam
                wrote on last edited by
                #19

                @Rondog
                When I run qmake I get the following : /Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/Src/qttools/.qmake.conf:1: Cannot find feature qt_build_config Could not find qmake configuration file macx-clang. Error processing project file: /Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/Src/qttools/src/macdeployqt/macdeployqt.pro

                And when I run make I get the following :
                make: *** No targets specified and no makefile found. Stop.

                Am I doing something wrong?

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Rondog
                  wrote on last edited by
                  #20

                  I am not sure how this should be done. I always download the sources and compile Qt for each OS that I plan to run on. For me it is as simple as opening a terminal window and entering the command 'make'.

                  If you open the macdeployqt program in QtCreator can you compile it from there?

                  Maybe try running the configure command from the folder qtbase of the source tree (this configures everything and creates all the make files) then run 'make' from the qttools folder.

                  There must be some notes somewhere about working with the sources from a pre-compiled version of Qt.

                  A 1 Reply Last reply
                  0
                  • R Rondog

                    I am not sure how this should be done. I always download the sources and compile Qt for each OS that I plan to run on. For me it is as simple as opening a terminal window and entering the command 'make'.

                    If you open the macdeployqt program in QtCreator can you compile it from there?

                    Maybe try running the configure command from the folder qtbase of the source tree (this configures everything and creates all the make files) then run 'make' from the qttools folder.

                    There must be some notes somewhere about working with the sources from a pre-compiled version of Qt.

                    A Offline
                    A Offline
                    Arqam
                    wrote on last edited by
                    #21

                    @Rondog I was getting the errors because I was using macdeployqt but when I used the full path /Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/bin/macdeployqt then it worked properly.

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

                      You have several versions of Qt installed ?

                      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

                      • Login

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