iam writing an C++ application with QT 5.3 using QT-Creator as IDE on mac os 10.8. The problem appears when iam trying to load the QMYSQL plugin with
db = QSqlDatabase::addDatabase("QMYSQL");
it results in
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
so I tried
loader.setFileName("/Users/kilian/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib");
qDebug() << loader.load();
qDebug() << loader.errorString();
to get a better output
"Die Bibliothek /Users/foob/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib kann nicht geladen werden:
(dlopen(/Users/foob/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib, 5):
Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/foob/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib
Reason: image not found)"
So I tried otool
otool -L build-$appname-Desktop-Debug/$appname.app/Contents/MacOS/$appname
build-$appname-Desktop-Debug/$appname.app/Contents/MacOS/$appname:
/usr/local/mysql/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
/Users/foob/Qt/5.3/clang_64/lib/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.3.0, current version 5.3.0)
/Users/foob/Qt/5.3/clang_64/lib/QtGui.framework/Versions/5/QtGui (compatibility version 5.3.0, current version 5.3.0)
/Users/foob/Qt/5.3/clang_64/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.3.0, current version 5.3.0)
/Users/foob/Qt/5.3/clang_64/lib/QtSql.framework/Versions/5/QtSql (compatibility version 5.3.0, current version 5.3.0)
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
As information, I built the QMYSQL Plugin by myself with
$cd Qt/5.3/Src/qtbase/src/plugins/sqldrivers/mysql/
$qmake "INCLUDEPATH+=/usr/local/mysql/include" "LIBS+=-L/usr/local/mysql/lib -lmysqlclient_r" mysql.pro
$ make
make -f Makefile.Release all
make[1]: Nothing to be done for `all'.
make -f Makefile.Debug all
make[1]: Nothing to be done for `all'.
$ make install
make -f Makefile.Release install
cp -f "../../../../plugins/sqldrivers/libqsqlmysql.dylib" "/Users/foob/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql.dylib"
cp -f /Users/foob/Qt/5.3/Src/qtbase/lib/cmake/Qt5Sql/Qt5Sql_QMYSQLDriverPlugin.cmake /Users/foob/Qt/5.3/clang_64/lib/cmake/Qt5Sql/
make -f Makefile.Debug install
cp -f "../../../../plugins/sqldrivers/libqsqlmysql_debug.dylib" "/Users/foob/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib"
cp -f /Users/foob/Qt/5.3/Src/qtbase/lib/cmake/Qt5Sql/Qt5Sql_QMYSQLDriverPlugin.cmake /Users/foob/Qt/5.3/clang_64/lib/cmake/Qt5Sql/
Everythink seems fine, i set earlier DYLD_LIBRARY_PATH in /etc/profile export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
echo $DYLD_LIBRARY_PATH
results in
/usr/local/mysql/lib:
The folder /usr/local/mysql/lib :
$ls -lisa /usr/local/mysql/lib/
total 556840
2147230 0 drwxr-xr-x 12 root wheel 408 21 Jun 00:01 .
2147093 0 drwxr-xr-x 17 root wheel 578 21 Jun 00:01 ..
2147231 8384 -rwxr-xr-x 1 root wheel 4289380 6 Mai 13:18 libmysqlclient.18.dylib
2147232 20744 -rw-r--r-- 1 root wheel 10620040 6 Mai 13:18 libmysqlclient.a
2147233 8 lrwxr-xr-x 1 root wheel 23 21 Jun 00:01 libmysqlclient.dylib -> libmysqlclient.18.dylib
2147234 8 lrwxr-xr-x 1 root wheel 23 21 Jun 00:01 libmysqlclient_r.18.dylib -> libmysqlclient.18.dylib
2147235 8 lrwxr-xr-x 1 root wheel 16 21 Jun 00:01 libmysqlclient_r.a -> libmysqlclient.a
2147236 8 lrwxr-xr-x 1 root wheel 20 21 Jun 00:01 libmysqlclient_r.dylib -> libmysqlclient.dylib
2147237 261360 -rw-r--r-- 1 root wheel 133814816 6 Mai 13:08 libmysqld-debug.a
2147239 266288 -rw-r--r-- 1 root wheel 136335512 6 Mai 13:18 libmysqld.a
2147240 32 -rw-r--r-- 1 root wheel 14544 6 Mai 13:18 libmysqlservices.a
2147241 0 drwxr-xr-x 17 root wheel 578 6 Mai 13:21 plugin
The related parts of the .pro file iam using
macx: {
INCLUDEPATH += /usr/local/mysql/include \
/Users/foob/Qt/5.3/clang_64/include
}
macx: {
LIBS += -L/usr/local/mysql/lib -lmysqld -lmysqlclient -v
}
Does anyone have an hint what iam doing wrong?
PS I changed User & App name for privacy.
Fixed the issue, wasn't aware its possible to use otool and install_name_tool for dylibs too. Simply did it with
install_name_tool -change libqsqlmysql_debug.dylib /Users/foob/Qt/5.3/Src/qtbase/plugins/sqldrivers/libqsqlmysql_debug.dylib Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib
Now it works. Does anyone knows why the libs aren't found in the first place? I checked the Makefile produced by qmake and it seems fine. Strange Mac ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.