如何解决使用静态 QT odbc 时的链接问题

问题描述 投票:0回答:2

我目前使用的是通过命令行配置的 Qt 4.7.4

-静态-调试和发布-开源-平台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 库必须以静态形式编译。

c++ qt linker odbc
2个回答
3
投票

您的 Qt 安装可能没问题。不过,当您使用 ODBC 时,应用程序必须与 odbc32.lib

 链接。为此,请将以下内容添加到您的 
.pro
 文件中:

LIBS += -lodbc32

使用动态库时不必这样做的原因是SQL ODBC插件.dll已经链接到

odbc32

。由于它是可执行格式(.dll/.exe)携带这些信息,而不是静态插件
.lib
,所以你必须自己处理它。

为了完全正确,有一种方法可以将链接器指令嵌入到目标文件中,然后将其捆绑在

.lib

 中,但 Qt 不使用这种方法,因为它使得推理完整的参数集变得更加困难传递给链接器 - 有些来自命令行,有些来自输入对象。


0
投票
这对我来说是救星,我花了几个小时寻找解决方案

© www.soinside.com 2019 - 2024. All rights reserved.