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. MySQL driver detected but not loading on MacOS
Forum Updated to NodeBB v4.3 + New Features

MySQL driver detected but not loading on MacOS

Scheduled Pinned Locked Moved Unsolved General and Desktop
62 Posts 8 Posters 11.6k Views 3 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.
  • J Offline
    J Offline
    juneleung
    wrote on 2 Sept 2022, 16:53 last edited by
    #41

    I had a similar problem,
    When I packaged the postgresql program, it was fine to run it locally, but when I opened the program on another computer, it prompted
    "QSqlDatabase: QPSQL driver not loaded.
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7",
    it seems that the driver of postgresql is not loaded.
    Why this the problem happened? Is there something wrong with the package? How should I set it?
    Could anyone guide me how to solve it?

    S 1 Reply Last reply 2 Sept 2022, 17:20
    0
    • J juneleung
      2 Sept 2022, 16:53

      I had a similar problem,
      When I packaged the postgresql program, it was fine to run it locally, but when I opened the program on another computer, it prompted
      "QSqlDatabase: QPSQL driver not loaded.
      QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7",
      it seems that the driver of postgresql is not loaded.
      Why this the problem happened? Is there something wrong with the package? How should I set it?
      Could anyone guide me how to solve it?

      S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 2 Sept 2022, 17:20 last edited by
      #42

      @juneleung hi and welcome to devnet,

      You have to deploy the PostgreSQL library along your application. Did you use macdeployqt to deploy your application ?

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

      J 1 Reply Last reply 2 Sept 2022, 17:24
      0
      • S SGaist
        2 Sept 2022, 17:20

        @juneleung hi and welcome to devnet,

        You have to deploy the PostgreSQL library along your application. Did you use macdeployqt to deploy your application ?

        J Offline
        J Offline
        juneleung
        wrote on 2 Sept 2022, 17:24 last edited by
        #43

        Hi @SGaist
        Yes, i have use macdeployqt to make it to a dmg file.
        but when open it in another MacBook, it cant link with sql and notice driven not loaded driven not loaded.

        A 1 Reply Last reply 2 Sept 2022, 17:28
        0
        • J juneleung
          2 Sept 2022, 17:24

          Hi @SGaist
          Yes, i have use macdeployqt to make it to a dmg file.
          but when open it in another MacBook, it cant link with sql and notice driven not loaded driven not loaded.

          A Offline
          A Offline
          artwaw
          wrote on 2 Sept 2022, 17:28 last edited by
          #44

          @juneleung AFAIR you need to manually deploy libpq.5.xx.dylib and relink your binary inside the .app to link to that - macdeployqt will not do it for you. I remember scripting that when I wrote a tool to interface with PostgreSQL. You'd need install-name-tool to do that.

          For more information please re-read.

          Kind Regards,
          Artur

          S 1 Reply Last reply 2 Sept 2022, 17:31
          0
          • A artwaw
            2 Sept 2022, 17:28

            @juneleung AFAIR you need to manually deploy libpq.5.xx.dylib and relink your binary inside the .app to link to that - macdeployqt will not do it for you. I remember scripting that when I wrote a tool to interface with PostgreSQL. You'd need install-name-tool to do that.

            S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 2 Sept 2022, 17:31 last edited by
            #45

            @artwaw not the binary, the plugin.

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

            A 1 Reply Last reply 2 Sept 2022, 17:38
            0
            • S SGaist
              2 Sept 2022, 17:31

              @artwaw not the binary, the plugin.

              A Offline
              A Offline
              artwaw
              wrote on 2 Sept 2022, 17:38 last edited by
              #46

              @SGaist You are right, of course, it's been a while since I dipped my fingers into this abyss.

              At any rate, I dug out my script, it will require some polishing but the gist is:

              #!/bin/zsh
              cp -fR ~/cpp/build-appName-Desktop_Qt_5_15_2_clang_64bit-Release/appName.app .
              macdeployqt appName.app -verbose=1 -always-overwrite
              cp -f *.dylib appName.app/Contents/Frameworks/
              install_name_tool -change /Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib @executable_path/../Frameworks/libpq.5.dylib appName/Contents/PlugIns/sqldrivers/libqsqlpsql.dylib
              install_name_tool -change libpq.5.dylib @executable_path/../Frameworks/libpq.5.dylib appName.app/Contents/MacOS/appName
              

              That works under assumption that you have all necessary Postgres files and your .app package in the same folder as the script. Or - at least - was working for the Qt 5.15.2.

              I replaced my app name with appName.

              For more information please re-read.

              Kind Regards,
              Artur

              J 1 Reply Last reply 2 Sept 2022, 17:53
              0
              • A artwaw
                2 Sept 2022, 17:38

                @SGaist You are right, of course, it's been a while since I dipped my fingers into this abyss.

                At any rate, I dug out my script, it will require some polishing but the gist is:

                #!/bin/zsh
                cp -fR ~/cpp/build-appName-Desktop_Qt_5_15_2_clang_64bit-Release/appName.app .
                macdeployqt appName.app -verbose=1 -always-overwrite
                cp -f *.dylib appName.app/Contents/Frameworks/
                install_name_tool -change /Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib @executable_path/../Frameworks/libpq.5.dylib appName/Contents/PlugIns/sqldrivers/libqsqlpsql.dylib
                install_name_tool -change libpq.5.dylib @executable_path/../Frameworks/libpq.5.dylib appName.app/Contents/MacOS/appName
                

                That works under assumption that you have all necessary Postgres files and your .app package in the same folder as the script. Or - at least - was working for the Qt 5.15.2.

                I replaced my app name with appName.

                J Offline
                J Offline
                juneleung
                wrote on 2 Sept 2022, 17:53 last edited by
                #47

                @artwaw Hi,
                I dont have any Postgres files' *.dylib in my app dir and my app/Contents/Plugins/sqldrivers/ folder dont have libqsqlpsql.dylib, only libqsqlite.dylib libqsqlodbc.dylib and libqsqlpsql.dylib.
                Where to make it create this dylib or where to copy it ? Which dylibs are postgresql needed?
                Thanks!

                A 1 Reply Last reply 2 Sept 2022, 18:50
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 2 Sept 2022, 18:44 last edited by
                  #48

                  libpq.5.dylib is provided through the PostgresApp.

                  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
                  • J juneleung
                    2 Sept 2022, 17:53

                    @artwaw Hi,
                    I dont have any Postgres files' *.dylib in my app dir and my app/Contents/Plugins/sqldrivers/ folder dont have libqsqlpsql.dylib, only libqsqlite.dylib libqsqlodbc.dylib and libqsqlpsql.dylib.
                    Where to make it create this dylib or where to copy it ? Which dylibs are postgresql needed?
                    Thanks!

                    A Offline
                    A Offline
                    artwaw
                    wrote on 2 Sept 2022, 18:50 last edited by
                    #49

                    @juneleung Like @SGaist said. It is old and well know problem (I really thought addressed by now) that the plugin links to Postgres installation, somewhere in /Application/Postgres.app/[...]/libpq.5.dylib and in order to deploy the program properly one has to dabble and relink. I got annoyed and bored and semiautomated the deployment as above (I also wrote myself some script tools for signing and notarisation, because lack of integration is prevalent on macOS).

                    Nonetheless - once you get hang on the particular quirks like this one, deploying on macOS is a relative breeze.

                    For more information please re-read.

                    Kind Regards,
                    Artur

                    J 1 Reply Last reply 2 Sept 2022, 19:01
                    0
                    • A artwaw
                      2 Sept 2022, 18:50

                      @juneleung Like @SGaist said. It is old and well know problem (I really thought addressed by now) that the plugin links to Postgres installation, somewhere in /Application/Postgres.app/[...]/libpq.5.dylib and in order to deploy the program properly one has to dabble and relink. I got annoyed and bored and semiautomated the deployment as above (I also wrote myself some script tools for signing and notarisation, because lack of integration is prevalent on macOS).

                      Nonetheless - once you get hang on the particular quirks like this one, deploying on macOS is a relative breeze.

                      J Offline
                      J Offline
                      juneleung
                      wrote on 2 Sept 2022, 19:01 last edited by
                      #50

                      @artwaw @SGaist

                      Hi, I use these cmd :

                      cp /Applications/Postgres.app/Contents/Versions/14/lib/libpq.5.14.dylib /Users/test/Build/build-test-Desktop_Qt_5_15_2_clang_64bit-Release/test.app/Contents/Frameworks/
                      
                      install_name_tool -change /Applications/Postgres.app/Contents/Versions/14/lib/libpq.5.dylib @executable_path/../Frameworks/libpq.5.14.dylib test/Contents/PlugIns/sqldrivers**/libqsqlpsql.dylib**
                      
                      install_name_tool -change libpq.5.dylib @executable_path/../Frameworks/libpq.5.14.dylib test.app/Contents/MacOS/test
                      

                      but an error with I don't have the libqsqlpsql.dylib in sqldrivers folder, and i can't found it in Applications/Postgres.app/Contents/Versions/14/lib/, where to find libqsqlpsql.dylib or how to make it generated automaticly by qt?

                      A 1 Reply Last reply 3 Sept 2022, 15:12
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 2 Sept 2022, 19:16 last edited by
                        #51

                        Might be a silly question but are you using the SQL module in your test app ?

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

                        J 1 Reply Last reply 3 Sept 2022, 04:50
                        0
                        • S SGaist
                          2 Sept 2022, 19:16

                          Might be a silly question but are you using the SQL module in your test app ?

                          J Offline
                          J Offline
                          juneleung
                          wrote on 3 Sept 2022, 04:50 last edited by juneleung 9 Mar 2022, 05:24
                          #52

                          @SGaist yes i have add sql in qt.

                          QT += sql
                          
                          QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
                          

                          The release package installed in local Macbook can open and link to sqldatabase, but move to another mac will get wrong driver.

                          Does I miss any steps when release packages?

                          1 Reply Last reply
                          0
                          • J juneleung
                            2 Sept 2022, 19:01

                            @artwaw @SGaist

                            Hi, I use these cmd :

                            cp /Applications/Postgres.app/Contents/Versions/14/lib/libpq.5.14.dylib /Users/test/Build/build-test-Desktop_Qt_5_15_2_clang_64bit-Release/test.app/Contents/Frameworks/
                            
                            install_name_tool -change /Applications/Postgres.app/Contents/Versions/14/lib/libpq.5.dylib @executable_path/../Frameworks/libpq.5.14.dylib test/Contents/PlugIns/sqldrivers**/libqsqlpsql.dylib**
                            
                            install_name_tool -change libpq.5.dylib @executable_path/../Frameworks/libpq.5.14.dylib test.app/Contents/MacOS/test
                            

                            but an error with I don't have the libqsqlpsql.dylib in sqldrivers folder, and i can't found it in Applications/Postgres.app/Contents/Versions/14/lib/, where to find libqsqlpsql.dylib or how to make it generated automaticly by qt?

                            A Offline
                            A Offline
                            artwaw
                            wrote on 3 Sept 2022, 15:12 last edited by artwaw 9 Mar 2022, 16:35
                            #53

                            @juneleung said in MySQL driver detected but not loading on MacOS:

                            I don't have the libqsqlpsql.dylib in sqldrivers folder, and i can't found it in Applications/Postgres.app/Contents/Versions/14/lib/, where to find libqsqlpsql.dylib or how to make it generated automaticly by qt?

                            That what's macdeployqt should do, if memory serves. Important - can't my be with option App Store compatible. It is Qt plugin, should be deployed.

                            For more information please re-read.

                            Kind Regards,
                            Artur

                            J 1 Reply Last reply 3 Sept 2022, 15:28
                            0
                            • A artwaw
                              3 Sept 2022, 15:12

                              @juneleung said in MySQL driver detected but not loading on MacOS:

                              I don't have the libqsqlpsql.dylib in sqldrivers folder, and i can't found it in Applications/Postgres.app/Contents/Versions/14/lib/, where to find libqsqlpsql.dylib or how to make it generated automaticly by qt?

                              That what's macdeployqt should do, if memory serves. Important - can't my be with option App Store compatible. It is Qt plugin, should be deployed.

                              J Offline
                              J Offline
                              juneleung
                              wrote on 3 Sept 2022, 15:28 last edited by
                              #54

                              @artwaw said in MySQL driver detected but not loading on MacOS:

                              That what's macdeployqt should do, if memory serves. Important - can't my with option App Store compatible. It is Qt plugin, should be deployed.

                              my macdeployqt step is :
                              macdeployqt /Users/test/Build/build-test-Desktop_Qt_5_15_2_clang_64bit-Release/test.app -dmg

                              any args should added to generate libqsqlpsql.dylib? or any step to setup at release mode?
                              Thanks!

                              A 1 Reply Last reply 3 Sept 2022, 16:39
                              0
                              • J juneleung
                                3 Sept 2022, 15:28

                                @artwaw said in MySQL driver detected but not loading on MacOS:

                                That what's macdeployqt should do, if memory serves. Important - can't my with option App Store compatible. It is Qt plugin, should be deployed.

                                my macdeployqt step is :
                                macdeployqt /Users/test/Build/build-test-Desktop_Qt_5_15_2_clang_64bit-Release/test.app -dmg

                                any args should added to generate libqsqlpsql.dylib? or any step to setup at release mode?
                                Thanks!

                                A Offline
                                A Offline
                                artwaw
                                wrote on 3 Sept 2022, 16:39 last edited by
                                #55

                                @juneleung Pls check your package under path:

                                ls test.app/Contents/PlugIns/sqldrivers
                                libqsqlite.dylib	libqsqlodbc.dylib	libqsqlpsql.dylib
                                

                                That's how it should be after the deploy.
                                You can pass verbose=2 to have more data on how deployment goes (I recommend together with overwrite option, this way you'll be able to see every copied file). Caution, this would be very verbose.

                                For more information please re-read.

                                Kind Regards,
                                Artur

                                J 1 Reply Last reply 3 Sept 2022, 17:38
                                0
                                • A artwaw
                                  3 Sept 2022, 16:39

                                  @juneleung Pls check your package under path:

                                  ls test.app/Contents/PlugIns/sqldrivers
                                  libqsqlite.dylib	libqsqlodbc.dylib	libqsqlpsql.dylib
                                  

                                  That's how it should be after the deploy.
                                  You can pass verbose=2 to have more data on how deployment goes (I recommend together with overwrite option, this way you'll be able to see every copied file). Caution, this would be very verbose.

                                  J Offline
                                  J Offline
                                  juneleung
                                  wrote on 3 Sept 2022, 17:38 last edited by juneleung 9 Mar 2022, 18:26
                                  #56

                                  @artwaw
                                  Thanks for your guide and I have generated the dylib successfully. :)

                                  in the /Applications/Postgres.app/Contents/Versions/14/lib/, my libpq.5.dylib looks is an alias, so i copy the libpq.5.14.dylib to /Users/test/Build/build-GiraffeL-Desktop_Qt_5_15_2_clang_64bit-Release/test.app/Contents/Frameworks/libpq.5.14.dylib, is it correct to copy libpq.5.14.dylib or I should copy the libpq.5.dylib alias file .

                                  004a2586-b94c-45a9-a755-0730cf92747e-image.png

                                  and before running with :

                                  cp /Applications/Postgres.app/Contents/Versions/14/lib/libpq.5.14.dylib /Users/test/Build/build-test-Desktop_Qt_5_15_2_clang_64bit-Release/test.app/Contents/Frameworks/
                                  
                                  install_name_tool -change /Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib @executable_path/../Frameworks/libpq.5.14.dylib /Users/test/Build/build-test-Desktop_Qt_5_15_2_clang_64bit-Release/test.app/Contents/PlugIns/sqldrivers/libqsqlpsql.dylib
                                  
                                  **install_name_tool -change libpq.5.dylib @executable_path/../Frameworks/libpq.5.14.dylib /Users/test/Build/build-test-Desktop_Qt_5_15_2_clang_64bit-Release/test.app/Contents/MacOS/test**
                                  

                                  I use otool to check test.app/Contents/MacOS/test

                                  otool -L test.app/Contents/MacOS/test
                                  

                                  but it looks don't have the libpq.5.dylib in the print list.
                                  is it correct to install_name_tool the libpq.5.dylib path for the test.app/Contents/MacOS/test? or another file?

                                  1 Reply Last reply
                                  1
                                  • A Offline
                                    A Offline
                                    artwaw
                                    wrote on 3 Sept 2022, 19:03 last edited by
                                    #57

                                    I used Contents/Frameworks path as it seems to be aligned with what macOS is expecting.
                                    if you look at my example deploy script above you'll see that I copy libpq* files there.
                                    Then install_name_tool of course.

                                    If you check otool (and my script) you'll see exactly what needs to linked to what.

                                    For more information please re-read.

                                    Kind Regards,
                                    Artur

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 3 Sept 2022, 19:15 last edited by
                                      #58

                                      @artwaw is correct, the application bundle has rules with regards to what goes where. See the Apple documentation.

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

                                      A 1 Reply Last reply 3 Sept 2022, 19:20
                                      0
                                      • S SGaist
                                        3 Sept 2022, 19:15

                                        @artwaw is correct, the application bundle has rules with regards to what goes where. See the Apple documentation.

                                        A Offline
                                        A Offline
                                        artwaw
                                        wrote on 3 Sept 2022, 19:20 last edited by
                                        #59

                                        @SGaist Yes. I forgot to link this, thank you.

                                        For more information please re-read.

                                        Kind Regards,
                                        Artur

                                        J 1 Reply Last reply 4 Sept 2022, 02:41
                                        0
                                        • A artwaw
                                          3 Sept 2022, 19:20

                                          @SGaist Yes. I forgot to link this, thank you.

                                          J Offline
                                          J Offline
                                          juneleung
                                          wrote on 4 Sept 2022, 02:41 last edited by juneleung 9 Jun 2022, 17:11
                                          #60

                                          @artwaw

                                          Sorry, maybe I didn't explain clearly.

                                          I have copied the libpq.5.dylib to the framework folder,

                                          In your previous code

                                          install_name_tool -change libpq.5.dylib @executable_path/../Frameworks/libpq.5.dylib appName.app/Contents/MacOS/appName
                                          

                                          it looks like changing the link path in the app file, is this pointing to the app? Or point to another file? Cause I checked the app file (test.app/Contents/MacOS/test) by otool, but in the printed link list, I don't see any information about libpq.5 .dylib part, is this normal?

                                          because there is no part of libpq.5.dylib, so I modified install_name_tool seems doesn't work either?

                                          1 Reply Last reply
                                          0

                                          41/62

                                          2 Sept 2022, 16:53

                                          • Login

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