MySQL driver detected but not loading on MacOS
-
@jsulm I just fixed the problem. Let me just explain how I found the problem step by step. (macOS)
- I prefer the Docker base PostgreSQL and install the Homebrew version of PostgreSQL. This is convenient to me because every upgrade apps can be done by a single command, $ brew upgrade.
- I activated QT_DEBUG_PLUGINS = 1 in the Qt Creator Environment setting. I have struggled to figure out how to do it, because I am a beginner for the Qt development situation. I have not understand what your are talking about.
- I followed the detailed debug message and found out the problem is the Qt is looking for the relevant QPSQL library based on the assumption such that the user has installed the PostgreSQL by using the PostgreSQL App.
- Problem is here: The Qt engineers could give a priority to the PostgreSQL.App installation but they has to consider the directory search for the users with Homebrew or the other installation methods as well.
- So I installed the PostgreSQL.App by downloading from the PostgreSQL website, stop the existing docker, runt the PostgreSQL.App and stop it followed by run the docker again. Then I compiled my source code again and I got it.
- It is recommended to consider the configuration the QPSQL driver, and also the other drivers, other mfethod/directory installations. The Unix command, "which", may give the hint to figure out the user preference. I hope the Qt engineers may consider the various situations with little bit clever way.
Thanks for your interests.
@In-Gee said in MySQL driver detected but not loading on MacOS:
I hope the Qt engineers may consider the various situations with little bit clever way
You could file a change request in Qt Bug Tracker: https://bugreports.qt.io/secure/Dashboard.jspa
-
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? -
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?@juneleung hi and welcome to devnet,
You have to deploy the PostgreSQL library along your application. Did you use macdeployqt to deploy your application ?
-
@juneleung hi and welcome to devnet,
You have to deploy the PostgreSQL library along your application. Did you use macdeployqt to deploy your application ?
-
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.@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. -
@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. -
@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.
-
@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.
@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! -
libpq.5.dylib
is provided through the PostgresApp. -
@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!@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.
-
@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.
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?
-
Might be a silly question but are you using the SQL module in your test app ?
-
@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?
-
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?
@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
mybe with option App Store compatible. It is Qt plugin, should be deployed. -
@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
mybe with option App Store compatible. It is Qt plugin, should be deployed.@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 -dmgany args should added to generate libqsqlpsql.dylib? or any step to setup at release mode?
Thanks! -
@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 -dmgany args should added to generate libqsqlpsql.dylib? or any step to setup at release mode?
Thanks!@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 passverbose=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. -
@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 passverbose=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.@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 .
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? -
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.
Theninstall_name_tool
of course.If you check
otool
(and my script) you'll see exactly what needs to linked to what. -
@artwaw is correct, the application bundle has rules with regards to what goes where. See the Apple documentation.
-
@artwaw is correct, the application bundle has rules with regards to what goes where. See the Apple documentation.