QMYSQL plugin (libqsqlmysql.dylib) fails with macOS on Apple Silicon M1
-
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!
-
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
-
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!
-
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.
-
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.
@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... -
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.
-
Yes. I tried both. The one mysql-8.0.29-macos12-arm64 failed to build. (see my second post above)
-
@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.
@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? -
@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? -
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
-
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
@hskoglund Thank you, that is very helpful!