MySQL connector/C++ 错误 "Unresolved external symbol _get_driver_instance" Visual Studio 2017

MySQL connector/C++ error "Unresolved external symbol _get_driver_instance" in Visual Studio 2017

我知道这个话题在这个论坛上很常见,但是在研究解决方案之后我仍然无法解决这个问题。

我做了开发者指南中的所有内容:

当我尝试构建示例代码时,它看起来像这样:

/* 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)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl;
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;
}

输出如下所示:

1>------ Build started: Project: MySQL test, Configuration: Release Win32 ------
1>MySQL test.cpp
1>Info: Boost.Config is older than your compiler version - probably nothing bad will happen - but you may wish to look for an update Boost version.  Define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE to suppress this message.
1>MySQL test.obj : error LNK2001: unresolved external symbol _get_driver_instance
1>C:\Users\rafal\source\repos\MySQL test\Release\MySQL test.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "MySQL test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Boost 库版本是 1_66_0,这是最新的。

配置属性/C/C++/常规/附加包含目录:C:\boost; C:\程序 Files\MySQL\MySQL 连接器 C++ 1.1.9\include

配置属性/C/C++/预处理器/预处理器定义:WIN32l;调试; _安慰; CPPCONN_PUBLIC_FUNC=

配置属性/链接器/常规/附加库目录:C:\Program Files\MySQL\MySQL Connector C++ 1.1.9\lib\opt

配置属性/链接器/输入/附加依赖项:mysqlcppconn-static.lib

配置属性/链接器/命令行:

Debug
Release

我该怎么做才能避免出现此错误?

已安装的二进制文件(我真的不想从源代码构建,除非我绝对必须这样做)

你绝对必须这样做。

在撰写此答案时,Visual studio 2017 (VC 15) 没有官方二进制文件。正如我在官方下载中检查的那样,二进制文件适用于 Visual studio 2013 - VC 12.