Stuck creating MySQL drivers on Mac OS
-
Hello, I've been trying to create the MySQL drivers for QT 6.4 on Mac OS Catalina, yet when i follow the instructions specified here, I get stuck executing the command
qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DMySQL_INCLUDE_DIR="/usr/local/mysql/include" -DMySQL_LIBRARY="/usr/local/mysql/lib/libmysqlclient.<so|dylib>"
This is a step by step of what I have done.
- Open Terminal
- Execute mkdir build-sqldrivers (Thus, creating the folder build-sqldrivers in /Users/santiagocarlos/)
- Execute cd build-sqldrivers
- Execute the command below:
/Users/Santiagocarlos/Qt/6.4.1/macos/bin/qt-cmake -G Ninja /Users/Santiagocarlos/Qt/6.4.1/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=/Users/Santiagocarlos/Qt/6.4.1/macos -DMySQL_INCLUDE_DIR="/usr/local/mysql/include" -DMySQL_LIBRARY="/usr/local/mysql/lib/libmysqlclient.dylib”
And this is where I got stuck. The only thing I can see in the terminal is this:
Here I don't know what to do. It doesn't matter what I try or type, when I press enter I get a new line with the dquote> prefix. This is another example:
Here I tried typing the commands cmake --build . and cmake --install . like it says in the Qt documentation. After this, if I finish the execution with Ctrl+C and I press de "up" arrow to see the last command I typed, I get this:
Which is weird, like it's stored or something.
I been dealing with this for the past few days and still don't get it, nor find any answer online.Does anybody know what should I do here? I'm really confused. Am I creating the folder build-sqldrivers in the correct directory? Should I type something special here? I appreciate any kind of help or guidance.
Thank you all in advance.
-
@jsulm Thanks! That did it. Although now I have a new problem, I have successfully installed the MySQL driver, but when I try to load it I still get the error QSqlDatabase: QMYSQL driver not loaded.
I set the QT_DEBUG_PLUGINS to 1 and I get the following:2022-12-06 03:41:51.207332-0300 ProyectoPola[33637:303361] [qt.core.library] "/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib" cannot load: Cannot load library /Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: @rpath/libmysqlclient.21.dylib Referenced from: /Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib Reason: image not found) 2022-12-06 03:41:51.207385-0300 ProyectoPola[33637:303361] [qt.core.plugin.loader] QLibraryPrivate::loadPlugin failed on "/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: @rpath/libmysqlclient.21.dylib\n Referenced from: /Users/santiagocarlos/Qt/6.4.1/macos/p lugins/sqldrivers/libqsqlmysql.dylib\n Reason: image not found)" 2022-12-06 03:41:51.207436-0300 ProyectoPola[33637:303361] QSqlDatabase: QMYSQL driver not loaded 2022-12-06 03:41:51.207494-0300 ProyectoPola[33637:303361] QSqlDatabase: available drivers: QSQLITE QMARIADB QMYSQL QODBC QPSQL 2022-12-06 03:41:51.207549-0300 ProyectoPola[33637:303361] db connection false
So, it seems like I can't load the driver, even though it's available.
Any idea how to solve this?
Thank you. -
@superg said in Stuck creating MySQL drivers on Mac OS:
Library not loaded: @rpath/libmysqlclient.21.dylib
The MySQL client library is not found. It is located in /usr/local/mysql which is not a path searched by default for libraries. There are different ways to solve this:
- Set LD_LIBRARY_PATH environment variable, so it points to /usr/local/mysql
- Copy the MySQL client library to your build folder
- Copy the MySQL client library to a folder searched by the system for libraries (like /usr/lib)
-
@jsulm Ok, I tried with the two first steps with no luck. I will try the third one later, I have to deactivate de SIP system of my mac.
Here is a screenshot were I show how I set LD_LIBRARY_PATH:
This is in "Run" under "Build & Run" in "projects".
I also copied the file libmysqlclient.21.dylib (found in /usr/local/mysql/lib) to the build folder of my project.
Have I done something wrong?
Thanks. -
@jsulm Ok, so this is what I get:
2022-12-07 22:13:59.642409-0300 ProyectoPola[49706:477072] [qt.core.plugin.factoryloader] Got keys from plugin meta data QList("QSQLITE") 2022-12-07 22:13:59.642606-0300 ProyectoPola[49706:477072] [qt.core.plugin.factoryloader] looking at "/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib" 2022-12-07 22:13:59.643509-0300 ProyectoPola[49706:477072] [qt.core.plugin.loader] Found metadata in lib /Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QMYSQL", "QMARIADB" ] }, "archlevel": 2, "className": "QMYSQLDriverPlugin", "debug": false, "version": 394240 } 2022-12-07 22:13:59.643583-0300 ProyectoPola[49706:477072] [qt.core.plugin.factoryloader] Got keys from plugin meta data QList("QMYSQL", "QMARIADB") 2022-12-07 22:13:59.643700-0300 ProyectoPola[49706:477072] [qt.core.plugin.factoryloader] looking at "/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlodbc.dylib" 2022-12-07 22:13:59.644751-0300 ProyectoPola[49706:477072] [qt.core.plugin.loader] Found metadata in lib /Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlodbc.dylib, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QODBC" ] }, "archlevel": 2, "className": "QODBCDriverPlugin", "debug": false, "version": 394240 } 2022-12-07 22:13:59.644800-0300 ProyectoPola[49706:477072] [qt.core.plugin.factoryloader] Got keys from plugin meta data QList("QODBC") 2022-12-07 22:13:59.644947-0300 ProyectoPola[49706:477072] [qt.core.plugin.factoryloader] looking at "/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlpsql.dylib" 2022-12-07 22:13:59.645977-0300 ProyectoPola[49706:477072] [qt.core.plugin.loader] Found metadata in lib /Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlpsql.dylib, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QPSQL" ] }, "archlevel": 2, "className": "QPSQLDriverPlugin", "debug": false, "version": 394240 } 2022-12-07 22:13:59.646016-0300 ProyectoPola[49706:477072] [qt.core.plugin.factoryloader] Got keys from plugin meta data QList("QPSQL") 2022-12-07 22:13:59.646039-0300 ProyectoPola[49706:477072] [qt.core.plugin.factoryloader] checking directory path "/Users/santiagocarlos/Trabajo/Polarímetro/build-ProyectoPola-Qt_6_4_1_for_macOS-Debug/ProyectoPola.app/Contents/MacOS/sqldrivers" ... 2022-12-07 22:13:59.653530-0300 ProyectoPola[49706:477072] [qt.core.library] "/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib" cannot load: Cannot load library /Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: @rpath/libmysqlclient.21.dylib Referenced from: /Users/santiagocarlos/Qt/6.4.1/macos/plugin s/sqldrivers/libqsqlmysql.dylib Reason: image not found) 2022-12-07 22:13:59.653574-0300 ProyectoPola[49706:477072] [qt.core.plugin.loader] QLibraryPrivate::loadPlugin failed on "/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: @rpath/libmysqlclient.21.dylib\n Referenced from: /Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib\n Reason: image not found)" 2022-12-07 22:13:59.653614-0300 ProyectoPola[49706:477072] QSqlDatabase: QMYSQL driver not loaded 2022-12-07 22:13:59.653662-0300 ProyectoPola[49706:477072] QSqlDatabase: available drivers: QSQLITE QMARIADB QMYSQL QODBC QPSQL 2022-12-07 22:13:59.653704-0300 ProyectoPola[49706:477072] db connection false
I think the output is basically the same as before I followed the steps you recommended, that why I asked if I had done something wrong.
Thanks again. -
@jsulm said in Stuck creating MySQL drivers on Mac OS:
- Copy the MySQL client library to your build folder
- Copy the MySQL client library to a folder searched by the system for libraries (like /usr/lib)
I have a question regarding this. What exactly do you mean by "Copy the MySQL client library to.."?
Are you referring to the file libmysqlclient.21.dylib found in /usr/local/mysql/lib? because that's what I copied. Should I copy the hole folder or something like that?Thanks in advance.
-
@superg said in Stuck creating MySQL drivers on Mac OS:
Are you referring to the file libmysqlclient.21.dylib
Yes.
"Should I copy the hole folder or something like that?" - maybe, depends whether libmysqlclient.21.dylib depends on other libraries in that folder. -
I just solved the issue following this video. Using the command provided in solution 1 did the trick.
The command I used is the following:sudo ln -s /usr/local/mysql/lib/libmysqlclient.21.dylib /usr/local/lib/libmysqlclient.21.dylib
The explanation of how this works is in that video, for anyone stepping with this problem in the future.
Thanks @jsulm for your help and time.