【发布时间】:2017-12-23 21:56:27
【问题描述】:
我正在尝试使用 Visual Studio 15 2017 构建 MySQL C++ 连接器应用程序,使用 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 示例脚本。
我尝试解决的一些问题:
- 将项目平台从 Win32 更改为 x64,将解决方案平台从 x86 更改为 x64(导致错误 LNK2038“检测到 '_MSC_VER' 不匹配:值 '1800' 与值 '1900' 不匹配”)
- 输入库的完整路径名
- 从源代码构建连接器/C++(不起作用,但不确定我是否正确)。
我已阅读有关此主题的大多数其他帖子,但解决方案似乎不起作用。有适用于 Windows 的解决方案吗?
【问题讨论】:
-
不,那篇文章是关于 linux 的
标签: c++ mysql visual-studio-2017