Total Newbie 使用 Visual Studio 2010 试用 SQLAPI,底部的代码是他们提供的确切示例,所以我相信代码没有问题。但当我尝试构建它时,它只是一直显示 LNK2019。
这些是错误:
错误 LNK2019:函数 __catch$_main$0 中引用了未解析的外部符号“public:virtual __thiscall SAConnection::~SAConnection(void)”(??1SAConnection@@UAE@XZ)
错误 LNK2019:函数 __catch$_main$0 中引用了未解析的外部符号“public: __thiscall SAString::operator char const *(void)const” (??BSAString@@QBEPBDXZ)
错误 LNK2019:未解析的外部符号“public: class SAString __thiscall SAException::ErrText(void)const” (?ErrText@SAException@@QBE?AVSAString@@XZ) 在函数 __catch$_main$0 中引用
错误 LNK2019:函数 __catch$_main$0 中引用了未解析的外部符号“public: void __thiscall SAConnection::Rollback(void)” (?Rollback@SAConnection@@QAEXXZ)
错误 LNK2019:未解析的外部符号“public: void __thiscall SAConnection::Disconnect(void)” (?Disconnect@SAConnection@@QAEXXZ) 在函数 _main 中引用
错误 LNK2019:未解析的外部符号“public: __thiscall SAString::~SAString(void)” (??1SAString@@QAE@XZ) 在函数 _main 中引用
错误 LNK2019:未解析的外部符号“public: void _thiscall SAConnection::Connect(class SAString const &,class SAString const &,class SAString const &,enum eSAClient,void (_cdecl*) (class SAConnection &,enum eSAConnectionHandlerType))"(?Connect@SAConnection@@QAEXABVSAString@@00W4eSAClient@@P6AXAAV1@W4eSAConnectionHandlerType@@@Z@Z) 在函数_main 中引用
错误 LNK2019:未解析的外部符号“public: __thiscall SAString::SAString(char const *)” (??0SAString@@QAE@PBD@Z) 在函数 _main 中引用
错误 LNK2019:未解析的外部符号“public: __thiscall SAConnection::SAConnection(void)” (??0SAConnection@@QAE@XZ) 在函数 _main 中引用
我在项目属性中的 C/C++ 和链接器的附加包含目录中添加了库说明。那么,我错过了什么?
提前致谢。
我正在尝试构建的代码:
int main(int argc, char* argv[])
{
SAConnection con; // create connection object
try
{
// connect to database
// in this example it is Oracle,
// but can also be Sybase, Informix, DB2
// SQLServer, InterBase, SQLBase and ODBC
con.Connect(
"DIGITALZONE\MSSQL", // database name
"DIGITALZONE\Digital10", // user name
"", // password
SA_Oracle_Client);
printf("We are connected!\n");
// Disconnect is optional
// autodisconnect will ocur in destructor if needed
con.Disconnect();
printf("We are disconnected!\n");
}
catch(SAException &x)
{
// SAConnection::Rollback()
// can also throw an exception
// (if a network error for example),
// we will be ready
try
{
// on error rollback changes
con.Rollback();
}
catch(SAException &)
{
}
// print error message
printf("%s\n", (const char*)x.ErrText());
}
return 0;
最佳答案
在项目属性->链接器选项卡的附加依赖项中指定sqlapi.lib。
关于c++ - 尝试使用 SQLAPI 时出现错误 LNK2019(Visual Studio 2010),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22061468/