QMYSQL driver not loaded on mac
-
Then just install the package you want from whatever source suits you best and change the
install_name_tool
call accordingly. -
OK man. Thank you for your attention :)
-
@SGaist Thanks for putting me on the right path. I solved my issue and just wanted to post what I learned for others to benefit from:
I had used install_name_tool to tell my PlugIns/sqldrivers/libqsqlmysql.dylib to find the libmysqlclient.dylib that was on my Mac (in my case installed using Homebrew). That worked fine until I deployed to other Macs and then they got the "Driver Not Loaded" error. I needed libqsqlmysql.dylib to link to something inside the app bundle.
It turns out that macdeployqt was copying libmysqlclient.dylib into my Frameworks directory (the output clearly shows this) but still, it didn't work!
ls -l Frameworks/*dylib -rw-r--r-- 1 1919816 22 libcrypto.1.0.0.dylib -rw-r--r-- 1 3723040 22 libmysqlclient.dylib -rw-r--r-- 1 375376 22 libssl.1.0.0.dylib
The first thing I noticed about this was that the file size of libmysqlclient.dylib was smaller after the copy:
/usr/local/Cellar/mysql/5.7.18/lib/libmysqlclient.dylib -> libmysqlclient.20.dylib /usr/local/Cellar/mysql/5.7.18/lib/libmysqlclient.20.dylib 3773144
3723040 vs 3773144 bytes? I was convinced this was the problem and wasted hours trying to figure it out. I still don't understand this, but it isn't the problem. It was a red herring.
The real problem is that libmysqlclient.dylib depends on those other 2 dylib's copied into the Frameworks directory by macdeployqt: libssl.1.0.0.dylib and libcrypto.1.0.0.dylib. I ran otool -L on each in turn, and found that libssl.1.0.0.dylib was depending on a copy of libcrypto.1.0.0.dylib outside the app bundle (again the homebrew location).
So, I had to fix the dependency of two dylib's mid-way through my build steps:
make clean qmake -config release make macdeployqt MyApp.app -dmg
'make' creates MyApp.app but the Frameworks and Plugins aren't put inside it until the first execution of macdeployqt. After that, I go in and fix the dependencies:
cd MyApp.app/Contents/Frameworks install_name_tool -change /usr/local/Cellar/openssl/1.0.2l/lib/libcrypto.1.0.0.dylib @executable_path/../Frameworks/libcrypto.1.0.0.dylib libssl.1.0.0.dylib cd ../PlugIns/sqldrivers install_name_tool -change /usr/local/mysql/lib/libmysqlclient.dylib @executable_path/../Frameworks/libmysqlclient.dylib libqsqlmysql.dylib cd ../../../.. rm -rf MyApp.dmg macdeployqt MyApp.app -dmg
After fixing the dependencies with install_name_tool, I come back to the top-level directory and delete the DMG created by that run of macdeployqt. The second time macdeployqt is executed it does not replace MyApp.app. It just complains that much of what it was going to do is done already. For example:
File exists, skip copy: "MyApp.app/Contents/PlugIns/sqldrivers/libqsqlmysql.dylib"
The second execution of macdeployqt creates the DMG with the correctly-linked dylibs.
If someone else has a similar problem, don't just copy the above steps. Use the otool -L tool on the dylibs in your app bundle to see where the dependencies are expected to be, then check to see if they are actually there. If you are deploying your app bundle to somewhere else, consider which dylib's need to be copied into your app bundle and which you can count on being on the target Mac. Finally, use install_name_tool to fix your dependencies. Hope this helps!
-
im using qt 5.9 and isolated install on mysql 5.7.20 on mac this piece of code worked like charm for me
brew install mysql-connector-c
I already had MAMP installed.... and wanted to use the mysql from mamp running on port 8889 this code helped me to do that
```
db.setHostName("localhost");
db.setConnectOptions("UNIX_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock");
db.setDatabaseName("xxxxxx");
db.setUserName("root");
db.setPassword("root");
db.setPort(8889); -
@edwinxxxx said in QMYSQL driver not loaded on mac:
/Users/lucas/Qt5.9.8/5.9.8/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
You can't execute a library.
What are you trying to do? -
@edwinxxxx Please tell us the exact step your executing when you get that error message
-
@edwinxxxx The last thig you did does not make sense: you're trying to execute a lib.
The first one was not successful - you called it in a wrong way. Take a look at its output ("Usage:"), it explains how to call it.
@SGaist - you're the Mac expert, can you take a look? -
@edwinxxxx so it's now working correctly ?
-
@sgaist
platform: macos 10.14
mysql 8.0.17
qt 5.9.8firstly i run
//otool -L libqsqlmysql.dylib
but it shows
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump: 'libqsqlmysql.dylib': No such file or directory
how can i find the path like "opt/local..." on my machine?
thanks man. -
@edwinxxxx said in QMYSQL driver not loaded on mac:
how can i find the path like "opt/local..." on my machine?
find / -name libqsqlmysql.dylib
-
@edwinxxxx "/opt" is a system folder just under root /
-
@edwinxxxx No, it doesn't mean that. If it is somewhere on your machine you can find it.
Where did you install it?
Did you try what I suggested?find / -name libmysqlclient.*.dylib
-
@edwinxxxx So, it is in /usr/local, not /opt/local.