Can't create MYSQL plugin in MacOS.
-
Hello,
For the past two days I've been trying to create the MYSQL driver following this official QT documentation. The problem is when I try to execute the following command:/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.<so|dylib>"
I get the error:
CMake Error: The source directory "/Users/santiagocarlos/Qt/build-sqldrivers/Qt/6.4.1/Src/qtbase/src/plugins/sqldrivers" does not exist.
Can someone please help me with this? I really don't know what to do.
A few this I want to clarify:
- I have to execute the qt-cmake script with the prefix /Users/Santiagocarlos/Qt/6.4.1/macos/bin/qt-cmake because adding the path to qt-cmake with the command "export PATH=$PATH:~/Users/santiagocarlos/Qt/6.4.1/macos/bin/qt-cmake" doesn't work. I just get "zsh: command not found: qt-cmake"
- I'm using Qt 6.4.1 in MacOS Catalina 10.15.7.
Here is a visual example:
The folder build-sqldrivers is created on Users/santiagocarlos.
Thank you in advance.
UPDATE:
I tried running qt-cmake from my directory Users/santiagocarlos and it worked, but I got the following error:
-- Configuring done -- Generating done CMake Error: Running '/usr/local/bin/ninja' '-C' '/Users/santiagocarlos' '-t' 'recompact' failed with: ninja: error: build.ninja:170: expected newline, got '|'
Does anyone know how to fix this?
-
@superg said in Can't create MYSQL plugin in MacOS.:
/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.<so|dylib>"
Check the paths you have in this command: many of them do not have leading /
For example: -DCMAKE_INSTALL_PREFIX=Users/santiagocarlos/Qt/6.4.1/macosAlso, here: /lib/libmysqlclient.<so|dylib> you need to change to /lib/libmysqlclient.dylib
<so|dylib> is just a placeholder and you need to change it to what is used on your system (MacOS uses dylib extension). -
@jsulm thank you very much for your help, the drivers creation worked. Nonetheless, I have a new problem. When I try to make connection it still tells me the driver is not loaded, but it shows that it's available.
This is the output: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-11-25 04:04:43.910863-0300 ProyectoPola[84792:1138343] QSqlDatabase: QMYSQL driver not loaded 2022-11-25 04:04:43.910907-0300 ProyectoPola[84792:1138343] QSqlDatabase: available drivers: QSQLITE QMARIADB QMYSQL QODBC QPSQL 2022-11-25 04:04:43.910951-0300 ProyectoPola[84792:1138343] db connection false
Do you know how can I solve this? I've tried with the following commands, but it didn't do anything.
1. cd /Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers 2. install_name_tool -change libmysqlclient.21.dylib /usr/local/mysql/lib/libmysqlclient.21.dylib /Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlmysql.dylib
Thanks in advance.
-
@superg said in Can't create MYSQL plugin in MacOS.:
Do you know how can I solve this?
Probably MySQL client lib is not found.
Set QT_DEBUG_PLUGINS variable before starting your app and check the output: you should see why the plug-in was not loaded. See https://doc.qt.io/qt-6/debug.html -
@jsulm said in Can't create MYSQL plugin in MacOS.:
Thanks for the help. I set the enviroment variable QT_DEBUG_PLUGINS and I found the following:
2022-11-25 18:03:54.665614-0300 ProyectoPola[85531:1148132] [qt.core.plugin.factoryloader] Got keys from plugin meta data QList("QMYSQL", "QMARIADB") 2022-11-25 18:03:54.665680-0300 ProyectoPola[85531:1148132] [qt.core.plugin.factoryloader] looking at "/Users/santiagocarlos/Qt/6.4.1/macos/plugins/sqldrivers/libqsqlodbc.dylib" 2022-11-25 18:03:54.665830-0300 ProyectoPola[85531:1148132] [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 }
So, it finds a key for QMYSQL, but a few lines below I get this:
2022-11-25 18:03:54.673034-0300 ProyectoPola[85531:1148132] [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-11-25 18:03:54.673093-0300 ProyectoPola[85531:1148132] [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-11-25 18:03:54.673121-0300 ProyectoPola[85531:1148132] QSqlDatabase: QMYSQL driver not loaded 2022-11-25 18:03:54.673168-0300 ProyectoPola[85531:1148132] QSqlDatabase: available drivers: QSQLITE QMARIADB QMYSQL QODBC QPSQL
So, when I try to add a database, Qt doesn't find the QMySQL driver.
Do you know how to solve this? I tried with the commands mentioned in my past reply with no luck, and every other solution that I found it's for windows, they do not work for me.
Thanks in advance.