首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQL连接器/C++在Visual 2017中出错“未解析的外部符号_get_driver_instance”

问MySQL连接器/C++在Visual 2017中出错“未解析的外部符号_get_driver_instance”
EN

Stack Overflow用户
提问于 2018-02-23 19:47:04
回答 1查看 652关注 0票数 1

我知道这个话题在这个论坛上是很常见的,但毕竟我仍然无法解决这个问题。

我从开发者指南中做了所有事情:

  • 链接Boost库
  • 链接连接器/C++静态库
  • 从调试切换到发布
  • 已安装的二进制文件(我真的不想从源代码构建,除非我必须这样做)

当我试图构建一个示例代码时,如下所示:

代码语言:javascript
复制
/* 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;
}

输出如下:

代码语言:javascript
复制
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++ / General /附加包含目录: C:\boost;C:\Program \MySQL\MySQL连接器C++ 1.1.9\include

配置属性/ C/C++ /预处理器/预处理定义: WIN32l;NDEBUG;_CONSOLE;CPPCONN_PUBLIC_FUNC=

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

配置属性/ Linker / Input /附加依赖项: mysqlcppconn-static.lib

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

调试

发布

我能做些什么来避免这个错误呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-17 23:56:41

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

你绝对得这么做。

在撰写此答案时,Visual 2017 (VC 15)还没有正式的二进制文件。正如我在官方下载中所看到的那样,二进制文件是用于Visual 2013-VC 12的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48955227

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档