【发布时间】:2015-06-20 13:25:03
【问题描述】:
我有一个使用QtSql 的Qt 程序,我包含了标头(#include <QtSql/QtSql>),甚至运行了Run QMake 和rebuild,但是它引发了以下链接器错误:
Undefined symbols for architecture x86_64:
"QSqlDatabase::addDatabase(QString const&, QString const&)", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlDatabase::setDatabaseName(QString const&)", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlDatabase::defaultConnection", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlDatabase::open()", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlDatabase::QSqlDatabase()", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlDatabase::~QSqlDatabase()", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlDatabase::operator=(QSqlDatabase const&)", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlError::~QSqlError()", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlQuery::exec()", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlQuery::prepare(QString const&)", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlQuery::bindValue(QString const&, QVariant const&, QFlags<QSql::ParamTypeFlag>)", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlQuery::QSqlQuery(QString const&, QSqlDatabase)", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlQuery::~QSqlQuery()", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlDatabase::lastError() const", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlQuery::value(int) const", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"QSqlQuery::lastError() const", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
"operator<<(QDebug, QSqlError const&)", referenced from:
authcontroller::authenticate(QString const&, QString const&) in authcontroller.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我没有执行任何特殊步骤来设置 QtSql,也没有安装 SQLite 驱动程序,因为我的理解是它们已经包含在 Qt 安装中。
有什么想法吗? 我正在运行最新的 Qt 发行版
谢谢
【问题讨论】:
-
您是否将
QT += sql添加到您的.pro文件中?仅包含某个模块的标头是不够的,您还应该使用上述语法指定其用法。 -
是的 - 现在就这样做了,它奏效了。没有完全阅读 QtSQL 文档 :) 谢谢!