【问题标题】:Undefined symbols for architecture x86_64 Qt架构 x86_64 Qt 的未定义符号
【发布时间】:2015-06-20 13:25:03
【问题描述】:

我有一个使用QtSqlQt 程序,我包含了标头(#include <QtSql/QtSql>),甚至运行了Run QMakerebuild,但是它引发了以下链接器错误:

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 文档 :) 谢谢!

标签: qt qt5 qtsql


【解决方案1】:

正如 BaCaRoZzo 指出的,我需要将 QT += sql 放在 .pro 文件中

【讨论】:

  • 这是 any 模块的一般规则。您可以在顶部的“qmake”字段中检查要在任何类的文档中声明的特定模块名称。例如见QSqlDatabase
猜你喜欢
  • 2015-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-07
  • 2012-07-20
  • 1970-01-01
  • 2015-10-09
相关资源
最近更新 更多