我目前正在使用配置了命令行的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库必须以静态形式编译。
答案 0 :(得分:2)
您的Qt安装可能没问题。但是,当您使用ODBC时,应用程序must be linked会带有odbc32.lib
。为此,请将以下内容添加到.pro
文件中:
LIBS += -lodbc32
使用动态库时不必执行此操作的原因是SQL ODBC插件.dll已链接到odbc32
。由于它是包含此类信息的可执行格式(.dll / .exe),而不是静态插件.lib
,因此您必须自己处理它。
为了完全正确,有一种方法可以在目标文件中嵌入链接器指令,然后将它们捆绑在.lib
中,但这是Qt没有使用的方法,因为它使得更难以推理传递给链接器的完整参数集 - 有些来自命令行,有些则来自输入对象。