我使用QT-Creator作为IDE在mac os 10.8上用QT 5.3编写C ++应用程序。 当iam尝试使用
加载QMYSQL插件时出现问题db = QSqlDatabase::addDatabase("QMYSQL");
导致
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
所以我试过
loader.setFileName("/Users/kilian/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib");
qDebug() << loader.load();
qDebug() << loader.errorString();
获得更好的输出
"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)"
所以我试过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)
作为信息,我自己用
构建了QMYSQL插件$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看起来很好,我在/ etc / profile中设置了早期的DYLD_LIBRARY_PATH export DYLD_LIBRARY_PATH = / usr / local / mysql / lib:$ DYLD_LIBRARY_PATH
echo $DYLD_LIBRARY_PATH
结果
/usr/local/mysql/lib:
文件夹/ 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
使用
的.pro文件的相关部分macx: {
INCLUDEPATH += /usr/local/mysql/include \
/Users/foob/Qt/5.3/clang_64/include
}
macx: {
LIBS += -L/usr/local/mysql/lib -lmysqld -lmysqlclient -v
}
有没有人暗示我做错了什么?
P.S。我改变了User&amp;隐私的应用程序名称。
答案 0 :(得分:0)
解决了这个问题,我不知道可以使用otool和install_name_tool来实现dylibs。 只需用
完成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
现在它有效。有谁知道为什么首先找不到libs?我检查了qmake生成的Makefile,看起来很好。奇怪的Mac ......