使用静态 QT odbc 时如何解决链接问题
Posted
技术标签:
【中文标题】使用静态 QT odbc 时如何解决链接问题【英文标题】:How to resolve linking issues when using static QT odbc 【发布时间】:2015-08-21 12:23:28 【问题描述】:我目前正在使用通过命令行配置的 Qt 4.7.4
-static -debug-and-release -opensource -platform win32-msvc2010 -qt-sql-odbc -qt-sql-sqlite
在尝试重新运行未添加 SQL 库的原始工作程序后,我收到大约 30 个链接错误。
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLGetInfoW@20 referenced in function "public: class QChar __thiscall QODBCDriverPrivate::quoteChar(void)" (?quoteChar@QODBCDriverPrivate@@QAE?AVQChar@@XZ)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLSetConnectAttrW@16 referenced in function "public: bool __thiscall QODBCDriverPrivate::setConnectionOptions(class QString const &)" (?setConnectionOptions@QODBCDriverPrivate@@QAE_NABVQString@@@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLGetDiagRecW@32 referenced in function "class QString __cdecl qWarnODBCHandle(int,void *,int *)" (?qWarnODBCHandle@@YA?AVQString@@HPAXPAH@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLFreeHandle@8 referenced in function "public: virtual __thiscall QODBCResult::~QODBCResult(void)" (??1QODBCResult@@UAE@XZ)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLNumResultCols@8 referenced in function "protected: virtual bool __thiscall QODBCResult::reset(class QString const &)" (?reset@QODBCResult@@MAE_NABVQString@@@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLGetStmtAttrW@20 referenced in function "protected: virtual bool __thiscall QODBCResult::reset(class QString const &)" (?reset@QODBCResult@@MAE_NABVQString@@@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLExecDirectW@12 referenced in function "protected: virtual bool __thiscall QODBCResult::reset(class QString const &)" (?reset@QODBCResult@@MAE_NABVQString@@@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLSetStmtAttrW@16 referenced in function "protected: virtual bool __thiscall QODBCResult::reset(class QString const &)" (?reset@QODBCResult@@MAE_NABVQString@@@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLAllocHandle@12 referenced in function "protected: virtual bool __thiscall QODBCResult::reset(class QString const &)" (?reset@QODBCResult@@MAE_NABVQString@@@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLColAttributeW@28 referenced in function "class QSqlField __cdecl qMakeFieldInfo(class QODBCPrivate const *,int)" (?qMakeFieldInfo@@YA?AVQSqlField@@PBVQODBCPrivate@@H@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLDescribeColW@36 referenced in function "class QSqlField __cdecl qMakeFieldInfo(class QODBCPrivate const *,int)" (?qMakeFieldInfo@@YA?AVQSqlField@@PBVQODBCPrivate@@H@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLFetchScroll@12 referenced in function "protected: virtual bool __thiscall QODBCResult::fetch(int)" (?fetch@QODBCResult@@MAE_NH@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLFetch@4 referenced in function "protected: virtual bool __thiscall QODBCResult::fetchNext(void)" (?fetchNext@QODBCResult@@MAE_NXZ)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLGetData@24 referenced in function "protected: virtual class QVariant __thiscall QODBCResult::data(int)" (?data@QODBCResult@@MAE?AVQVariant@@H@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLRowCount@8 referenced in function "protected: virtual int __thiscall QODBCResult::numRowsAffected(void)" (?numRowsAffected@QODBCResult@@MAEHXZ)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLPrepareW@12 referenced in function "public: virtual bool __thiscall QODBCResult::prepare(class QString const &)" (?prepare@QODBCResult@@UAE_NABVQString@@@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLExecute@4 referenced in function "public: virtual bool __thiscall QODBCResult::exec(void)" (?exec@QODBCResult@@UAE_NXZ)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLBindParameter@40 referenced in function "public: virtual bool __thiscall QODBCResult::exec(void)" (?exec@QODBCResult@@UAE_NXZ)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLCloseCursor@4 referenced in function "public: virtual bool __thiscall QODBCResult::exec(void)" (?exec@QODBCResult@@UAE_NXZ)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLMoreResults@4 referenced in function "protected: bool __thiscall QODBCResult::nextResult(void)" (?nextResult@QODBCResult@@IAE_NXZ)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLDriverConnectW@32 referenced in function "public: virtual bool __thiscall QODBCDriver::open(class QString const &,class QString const &,class QString const &,class QString const &,int,class QString const &)" (?open@QODBCDriver@@UAE_NABVQString@@000H0@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLSetEnvAttr@16 referenced in function "public: virtual bool __thiscall QODBCDriver::open(class QString const &,class QString const &,class QString const &,class QString const &,int,class QString const &)" (?open@QODBCDriver@@UAE_NABVQString@@000H0@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLDisconnect@4 referenced in function "private: void __thiscall QODBCDriver::cleanup(void)" (?cleanup@QODBCDriver@@AAEXXZ)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLGetFunctions@12 referenced in function "public: bool __thiscall QODBCDriverPrivate::checkDriver(void)const " (?checkDriver@QODBCDriverPrivate@@QBE_NXZ)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLEndTran@12 referenced in function "protected: virtual bool __thiscall QODBCDriver::commitTransaction(void)" (?commitTransaction@QODBCDriver@@MAE_NXZ)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLTablesW@36 referenced in function "public: virtual class QStringList __thiscall QODBCDriver::tables(enum QSql::TableType)const " (?tables@QODBCDriver@@UBE?AVQStringList@@W4TableType@QSql@@@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLSpecialColumnsW@40 referenced in function "public: virtual class QSqlIndex __thiscall QODBCDriver::primaryIndex(class QString const &)const " (?primaryIndex@QODBCDriver@@UBE?AVQSqlIndex@@ABVQString@@@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLPrimaryKeysW@28 referenced in function "public: virtual class QSqlIndex __thiscall QODBCDriver::primaryIndex(class QString const &)const " (?primaryIndex@QODBCDriver@@UBE?AVQSqlIndex@@ABVQString@@@Z)
1>QtSqld.lib(qsql_odbc.obj) : error LNK2019: unresolved external symbol _SQLColumnsW@36 referenced in function "public: virtual class QSqlRecord __thiscall QODBCDriver::record(class QString const &)const " (?record@QODBCDriver@@UBE?AVQSqlRecord@@ABVQString@@@Z)
我假设我的链接参数中没有包含库,或者我没有正确配置 QT。
有人有这方面的经验吗?提醒一下,我知道在处理 SQL 插件时,将 QT 编译为非静态更容易,但目前 QT 库必须以静态形式编译。
【问题讨论】:
【参考方案1】:您的 Qt 安装可能没问题。但是,当您使用 ODBC 时,应用程序 must be linked 和 odbc32.lib
。为此,请将以下内容添加到您的 .pro
文件中:
LIBS += -lodbc32
使用动态库时不必这样做的原因是 SQL ODBC 插件 .dll 已经链接到 odbc32
。由于承载这些信息的是可执行格式(.dll/.exe),而不是静态插件.lib
,所以你必须自己处理。
为了完全正确,有一种方法可以将链接器指令嵌入到目标文件中,然后将其捆绑在 .lib
中,但这是 Qt 不使用的方法,因为它使得推理完整集变得更加困难传递给链接器的参数 - 有些来自命令行,有些则来自输入对象。
【讨论】:
这正是解决方案。非常感谢!以上是关于使用静态 QT odbc 时如何解决链接问题的主要内容,如果未能解决你的问题,请参考以下文章
如何在 静态编译的QT 5.5.1 中 使用数据库插件连接 ODBC(调用静态插件)