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. QMYSQL plugin (libqsqlmysql.dylib) fails with macOS on Apple Silicon M1

QMYSQL plugin (libqsqlmysql.dylib) fails with macOS on Apple Silicon M1

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 958 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.
  • xtophX Offline
    xtophX Offline
    xtoph
    wrote on last edited by
    #1

    I was following the instructions here to build the QMYSQL plugin for macOS (M1 chip) it worked, but I'm still having issues trying to use the plugin.

    I installed MySQL from Macports (as recommended here)

    sudo port install mysql8
    

    Since I could not find there the headers and the libmysqlclient.dylib, I downloaded them from https://dev.mysql.com/downloads/mysql/8.0.html (macOS 12 x86).

    Then I ran

    qt-cmake -G Ninja /Users/myname/Qt/6.2.4/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=/Users/myname/Qt/6.2.4/macos -DMySQL_INCLUDE_DIR="/path/to/include" -DMySQL_LIBRARY="/path/to/libmysqlclient.21.dylib"
    cmake --build .
    cmake --install .
    

    This completed successfully and I got my libqsqlmysql.dylib.

    When I try to use it with

    QPluginLoader loader("/Users/myname/Qt/6.2.4/macos/plugins/sqldrivers/libqsqlmysql.dylib");
    

    it fails and

    loader.errorString();
    

    returns:

    '/Users/myname/Qt/6.2.4/macos/plugins/sqldrivers/libqsqlmysql.dylib' is not a valid Mach-O binary (wrong architecture)
    

    Help would be very appreciated!

    jsulmJ 1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #11

      Hi, you are on the right track specifying -DCMAKE_OSX_ARCHITECTURES="arm64"
      but for it to work you also need to nuke/erase all the cmake caches
      (easiest is to delete all of the subdirectory /Users/myname/Qt/6.2.4/Src/qtbase/src/plugins/sqldrivers and download a fresh copy)

      This is a frequent topic on this forum, there a more posts on this here and here

      xtophX 1 Reply Last reply
      2
      • xtophX xtoph

        I was following the instructions here to build the QMYSQL plugin for macOS (M1 chip) it worked, but I'm still having issues trying to use the plugin.

        I installed MySQL from Macports (as recommended here)

        sudo port install mysql8
        

        Since I could not find there the headers and the libmysqlclient.dylib, I downloaded them from https://dev.mysql.com/downloads/mysql/8.0.html (macOS 12 x86).

        Then I ran

        qt-cmake -G Ninja /Users/myname/Qt/6.2.4/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=/Users/myname/Qt/6.2.4/macos -DMySQL_INCLUDE_DIR="/path/to/include" -DMySQL_LIBRARY="/path/to/libmysqlclient.21.dylib"
        cmake --build .
        cmake --install .
        

        This completed successfully and I got my libqsqlmysql.dylib.

        When I try to use it with

        QPluginLoader loader("/Users/myname/Qt/6.2.4/macos/plugins/sqldrivers/libqsqlmysql.dylib");
        

        it fails and

        loader.errorString();
        

        returns:

        '/Users/myname/Qt/6.2.4/macos/plugins/sqldrivers/libqsqlmysql.dylib' is not a valid Mach-O binary (wrong architecture)
        

        Help would be very appreciated!

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @xtoph What is the architecture of your Qt installation and the MySQL plug-in you built? It looks like you have a mix of x86 and ARM.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • xtophX Offline
          xtophX Offline
          xtoph
          wrote on last edited by xtoph
          #3

          Thanks for your fast reply!

          Qt 6.2.3 (arm64-little_endian-lp64 shared (dynamic) release build; by Clang 13.0.0 (clang-1300.0.29.3) (Apple)) on "cocoa" 
          OS: macOS 11.6 [darwin version 20.6.0]
          
          Architecture: arm64; features: Neon
          

          I also need to mention that I tried before lib and includes from mysql-8.0.29-macos12-arm64 but then cmake failed to build:

          cmake --build . -v
          [1/1] : && /Library/Developer/CommandLineTools/usr/bin/c++ -g -DNDEBUG -O2 -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -mmacosx-version-min=11 -bundle -Wl,-headerpad_max_install_names -Wl,-undefined,error -fapplication-extension -o plugins/sqldrivers/libqsqlmysql.dylib mysql/CMakeFiles/QMYSQLDriverPlugin.dir/QMYSQLDriverPlugin_autogen/mocs_compilation.cpp.o mysql/CMakeFiles/QMYSQLDriverPlugin.dir/main.cpp.o mysql/CMakeFiles/QMYSQLDriverPlugin.dir/qsql_mysql.cpp.o  -Wl,-rpath,/Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers -Wl,-rpath,/Users/myname/Qt/6.2.4/macos/lib  libmysqlclient.21.dylib  /Users/myname/Qt/6.2.4/macos/lib/QtSql.framework/Versions/A/QtSql  /Users/myname/Qt/6.2.4/macos/lib/QtCore.framework/Versions/A/QtCore  -framework DiskArbitration  -framework IOKit && cd /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/mysql && /opt/local/bin/cmake -E make_directory /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF && /opt/local/bin/cmake -E copy Info.dSYM.plist /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Info.plist && /usr/bin/dsymutil /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib --flat -o /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF/qsqlmysql && /Library/Developer/CommandLineTools/usr/bin/strip -S /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib && chmod -x /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF/qsqlmysql
          FAILED: plugins/sqldrivers/libqsqlmysql.dylib 
          : && /Library/Developer/CommandLineTools/usr/bin/c++ -g -DNDEBUG -O2 -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -mmacosx-version-min=11 -bundle -Wl,-headerpad_max_install_names -Wl,-undefined,error -fapplication-extension -o plugins/sqldrivers/libqsqlmysql.dylib mysql/CMakeFiles/QMYSQLDriverPlugin.dir/QMYSQLDriverPlugin_autogen/mocs_compilation.cpp.o mysql/CMakeFiles/QMYSQLDriverPlugin.dir/main.cpp.o mysql/CMakeFiles/QMYSQLDriverPlugin.dir/qsql_mysql.cpp.o  -Wl,-rpath,/Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers -Wl,-rpath,/Users/myname/Qt/6.2.4/macos/lib  libmysqlclient.21.dylib  /Users/myname/Qt/6.2.4/macos/lib/QtSql.framework/Versions/A/QtSql  /Users/myname/Qt/6.2.4/macos/lib/QtCore.framework/Versions/A/QtCore  -framework DiskArbitration  -framework IOKit && cd /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/mysql && /opt/local/bin/cmake -E make_directory /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF && /opt/local/bin/cmake -E copy Info.dSYM.plist /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Info.plist && /usr/bin/dsymutil /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib --flat -o /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF/qsqlmysql && /Library/Developer/CommandLineTools/usr/bin/strip -S /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib && chmod -x /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF/qsqlmysql
          ld: warning: ignoring file libmysqlclient.21.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
          Undefined symbols for architecture x86_64:
           "_mysql_affected_rows", referenced from:
               QMYSQLResult::reset(QString const&) in qsql_mysql.cpp.o
               QMYSQLResult::nextResult() in qsql_mysql.cpp.o
           "_mysql_character_set_name", referenced from:
               QMYSQLDriver::open(QString const&, QString const&, QString const&, QString const&, int, QString const&) (.cold.1) in qsql_mysql.cpp.o
           ... (many more of that kind)
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          ninja: build stopped: subcommand failed.
          

          I have also tried qt-make with -DCMAKE_OSX_ARCHITECTURES=arm64. No change.

          This looked to me like it still needs x86_64.

          jsulmJ 1 Reply Last reply
          0
          • xtophX xtoph

            Thanks for your fast reply!

            Qt 6.2.3 (arm64-little_endian-lp64 shared (dynamic) release build; by Clang 13.0.0 (clang-1300.0.29.3) (Apple)) on "cocoa" 
            OS: macOS 11.6 [darwin version 20.6.0]
            
            Architecture: arm64; features: Neon
            

            I also need to mention that I tried before lib and includes from mysql-8.0.29-macos12-arm64 but then cmake failed to build:

            cmake --build . -v
            [1/1] : && /Library/Developer/CommandLineTools/usr/bin/c++ -g -DNDEBUG -O2 -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -mmacosx-version-min=11 -bundle -Wl,-headerpad_max_install_names -Wl,-undefined,error -fapplication-extension -o plugins/sqldrivers/libqsqlmysql.dylib mysql/CMakeFiles/QMYSQLDriverPlugin.dir/QMYSQLDriverPlugin_autogen/mocs_compilation.cpp.o mysql/CMakeFiles/QMYSQLDriverPlugin.dir/main.cpp.o mysql/CMakeFiles/QMYSQLDriverPlugin.dir/qsql_mysql.cpp.o  -Wl,-rpath,/Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers -Wl,-rpath,/Users/myname/Qt/6.2.4/macos/lib  libmysqlclient.21.dylib  /Users/myname/Qt/6.2.4/macos/lib/QtSql.framework/Versions/A/QtSql  /Users/myname/Qt/6.2.4/macos/lib/QtCore.framework/Versions/A/QtCore  -framework DiskArbitration  -framework IOKit && cd /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/mysql && /opt/local/bin/cmake -E make_directory /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF && /opt/local/bin/cmake -E copy Info.dSYM.plist /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Info.plist && /usr/bin/dsymutil /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib --flat -o /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF/qsqlmysql && /Library/Developer/CommandLineTools/usr/bin/strip -S /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib && chmod -x /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF/qsqlmysql
            FAILED: plugins/sqldrivers/libqsqlmysql.dylib 
            : && /Library/Developer/CommandLineTools/usr/bin/c++ -g -DNDEBUG -O2 -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -mmacosx-version-min=11 -bundle -Wl,-headerpad_max_install_names -Wl,-undefined,error -fapplication-extension -o plugins/sqldrivers/libqsqlmysql.dylib mysql/CMakeFiles/QMYSQLDriverPlugin.dir/QMYSQLDriverPlugin_autogen/mocs_compilation.cpp.o mysql/CMakeFiles/QMYSQLDriverPlugin.dir/main.cpp.o mysql/CMakeFiles/QMYSQLDriverPlugin.dir/qsql_mysql.cpp.o  -Wl,-rpath,/Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers -Wl,-rpath,/Users/myname/Qt/6.2.4/macos/lib  libmysqlclient.21.dylib  /Users/myname/Qt/6.2.4/macos/lib/QtSql.framework/Versions/A/QtSql  /Users/myname/Qt/6.2.4/macos/lib/QtCore.framework/Versions/A/QtCore  -framework DiskArbitration  -framework IOKit && cd /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/mysql && /opt/local/bin/cmake -E make_directory /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF && /opt/local/bin/cmake -E copy Info.dSYM.plist /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Info.plist && /usr/bin/dsymutil /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib --flat -o /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF/qsqlmysql && /Library/Developer/CommandLineTools/usr/bin/strip -S /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib && chmod -x /Users/myname/Qt/6.2.4/macos/plugins/build-sqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF/qsqlmysql
            ld: warning: ignoring file libmysqlclient.21.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
            Undefined symbols for architecture x86_64:
             "_mysql_affected_rows", referenced from:
                 QMYSQLResult::reset(QString const&) in qsql_mysql.cpp.o
                 QMYSQLResult::nextResult() in qsql_mysql.cpp.o
             "_mysql_character_set_name", referenced from:
                 QMYSQLDriver::open(QString const&, QString const&, QString const&, QString const&, int, QString const&) (.cold.1) in qsql_mysql.cpp.o
             ... (many more of that kind)
            ld: symbol(s) not found for architecture x86_64
            clang: error: linker command failed with exit code 1 (use -v to see invocation)
            ninja: build stopped: subcommand failed.
            

            I have also tried qt-make with -DCMAKE_OSX_ARCHITECTURES=arm64. No change.

            This looked to me like it still needs x86_64.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @xtoph said in QMYSQL plugin (libqsqlmysql.dylib) fails with macOS on Apple Silicon M1:

            ld: warning: ignoring file libmysqlclient.21.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

            Apparently you tried to build Qt for x86_64 with ARM version of MySQL!
            Please make sure you use proper MySQL client library...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • xtophX Offline
              xtophX Offline
              xtoph
              wrote on last edited by
              #5

              Assuming that my version of Qt is correct, how can I build the plugin correctly? Picking a different version from MySQL apparently didn't make a difference.

              jsulmJ 1 Reply Last reply
              0
              • xtophX xtoph

                Assuming that my version of Qt is correct, how can I build the plugin correctly? Picking a different version from MySQL apparently didn't make a difference.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @xtoph As I said: use MySQL client library built for same architecture as your Qt (either both x86_64 or both ARM64).

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • xtophX Offline
                  xtophX Offline
                  xtoph
                  wrote on last edited by
                  #7

                  Yes. I tried both. The one mysql-8.0.29-macos12-arm64 failed to build. (see my second post above)

                  jsulmJ 1 Reply Last reply
                  0
                  • xtophX xtoph

                    Yes. I tried both. The one mysql-8.0.29-macos12-arm64 failed to build. (see my second post above)

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by jsulm
                    #8

                    @xtoph I already replied to that post and told you that you were mixing two architectures (as you can clearly see from the error). Please m ake sure you do not mich different architectures.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    xtophX 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @xtoph I already replied to that post and told you that you were mixing two architectures (as you can clearly see from the error). Please m ake sure you do not mich different architectures.

                      xtophX Offline
                      xtophX Offline
                      xtoph
                      wrote on last edited by
                      #9

                      @jsulm Just to summarize, maybe I misunderstand: I have Qt for arm64 and I used MySQL for arm64. Both are for the same architecture, so I am not not mixing anything, as far as I can see. Do you mean that there is another component involved that introduces a different architecture?
                      The question is, how to successfully run cmake --build. Do you have any hint where to search?

                      jsulmJ 1 Reply Last reply
                      0
                      • xtophX xtoph

                        @jsulm Just to summarize, maybe I misunderstand: I have Qt for arm64 and I used MySQL for arm64. Both are for the same architecture, so I am not not mixing anything, as far as I can see. Do you mean that there is another component involved that introduces a different architecture?
                        The question is, how to successfully run cmake --build. Do you have any hint where to search?

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @xtoph This warning contradicts with what you claim:

                        ld: warning: ignoring file libmysqlclient.21.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
                        

                        So, you ARE mixing architectures...

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • hskoglundH Offline
                          hskoglundH Offline
                          hskoglund
                          wrote on last edited by
                          #11

                          Hi, you are on the right track specifying -DCMAKE_OSX_ARCHITECTURES="arm64"
                          but for it to work you also need to nuke/erase all the cmake caches
                          (easiest is to delete all of the subdirectory /Users/myname/Qt/6.2.4/Src/qtbase/src/plugins/sqldrivers and download a fresh copy)

                          This is a frequent topic on this forum, there a more posts on this here and here

                          xtophX 1 Reply Last reply
                          2
                          • hskoglundH hskoglund

                            Hi, you are on the right track specifying -DCMAKE_OSX_ARCHITECTURES="arm64"
                            but for it to work you also need to nuke/erase all the cmake caches
                            (easiest is to delete all of the subdirectory /Users/myname/Qt/6.2.4/Src/qtbase/src/plugins/sqldrivers and download a fresh copy)

                            This is a frequent topic on this forum, there a more posts on this here and here

                            xtophX Offline
                            xtophX Offline
                            xtoph
                            wrote on last edited by
                            #12

                            @hskoglund Thank you, that is very helpful!

                            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