我正在尝试使用MySQL C ++连接器作为静态库,使用Visual Studio 15 2017构建MySQL C ++连接器应用程序。但是,在仔细按照https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-apps-windows-visual-studio.html给出的指示后,我得到了LNK2001错误“未解析的外部符号_get_driver_instance”。
以上图片显示了我根据上述链接设置的所需库设置和其他设置。
我想要构建的代码是:
/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>
/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
int main(void)
{
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
cout << res->getString("_message") << endl;
cout << "\t... MySQL says it again: ";
/* Access column data by numeric offset, 1 is the first column */
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete con;
}
catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line "
<< __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}
来自MySQL示例脚本。
我试图解决问题的一些事情:
我已阅读过有关此主题的大多数其他帖子,但解决方案似乎无效。是否有适用于Windows的解决方案?
答案 0 :(得分:0)
将您的路径放在引号中(因为空格),即
"C:\Program Files\MySQL\Connector C++ 1.1\lib\opt";
"C:\Program Files\MySQL\Connector C++ 1.1\include";...
另外,请确保列出了Linker
- &gt;中所需的所有库。 Input
设置部分。
答案 1 :(得分:0)
在Windows上使用MySQL连接器/ c ++而不从源构建Visual Studio 2013必须与32位连接器/ c ++库一起使用。我不得不专门下载32位库。