简体   繁体   English

Visual Studio 2017中的MySQL连接器/ C ++错误“无法解析的外部符号_get_driver_instance”

[英]MySQL connector/C++ error “Unresolved external symbol _get_driver_instance” in Visual Studio 2017

I know this topic is common on this forum, but after all researching for solution I still cannot make it work. 我知道这个话题在这个论坛上很普遍,但是在寻找解决方案之后,我仍然无法使它起作用。

I did everything from Developer Guide: 我做了《开发人员指南》中的所有内容:

  • Linked Boost libraries 链接的Boost库
  • Linked Connector/C++ static library 链接的连接器/ C ++静态库
  • Switched from Debug to Release 从调试切换到发布
  • Installed binary (I really don't want to build from source unless I absolutly have to) 已安装的二进制文件(除非绝对要,否则我真的不想从源代码进行构建)

When I am trying to build an example code, which looks like this: 当我尝试构建示例代码时,如下所示:

/* 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;
}

Output looks like this: 输出看起来像这样:

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 libraries version is 1_66_0, that's the latest one. Boost库的版本是1_66_0,这是最新版本。

Configuration Properties / C/C++ / General / Additional Include Directories: C:\\boost; 配置属性/ C / C ++ /常规/其他包含目录:C:\\ boost; C:\\Program Files\\MySQL\\MySQL Connector C++ 1.1.9\\include C:\\ Program Files \\ MySQL \\ MySQL Connector C ++ 1.1.9 \\ include

Configuration Properties / C/C++ / Preprocessor / Preprocessor Definicions: WIN32l; 配置属性/ C / C ++ /预处理程序/预处理程序定义:WIN32l; NDEBUG; NDEBUG; _CONSOLE; _安慰; CPPCONN_PUBLIC_FUNC= CPPCONN_PUBLIC_FUNC =

Configuration Properties / Linker / General / Additional Library Directories: C:\\Program Files\\MySQL\\MySQL Connector C++ 1.1.9\\lib\\opt 配置属性/链接器/常规/其他库目录:C:\\ Program Files \\ MySQL \\ MySQL Connector C ++ 1.1.9 \\ lib \\ opt

Configuration Properties / Linker / Input / Additional Dependencies: mysqlcppconn-static.lib 配置属性/链接器/输入/其他依赖项:mysqlcppconn-static.lib

Configuration Properties / Linker / Command Line: 配置属性/链接器/命令行:

Debug 除错
Release 发布

What can I do to not get this error? 我该怎么办才能避免出现此错误?

Installed binary (I really don't want to build from source unless I absolutly have to) 已安装的二进制文件(除非绝对要,否则我真的不想从源代码进行构建)

You're gonna absolutely have to. 您绝对必须。

There are no official binaries for Visual studio 2017 (VC 15) at the moment of writing of this answer. 在撰写此答案时,还没有Visual Studio 2017(VC 15)的官方二进制文件。 As I've checked in official downloads, binaries are for Visual studio 2013 - VC 12. 正如我已经检查了官方下载一样,二进制文件适用于Visual Studio 2013-VC 12。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL C ++连接器无法解析的外部符号_get_driver_instance - MySQL C++ Connector unresolved external symbol _get_driver_instance MySQL C++ 连接器:对“get_driver_instance”的未定义引用 - MySQL C++ Connector: undefined reference to `get_driver_instance' 未解析的符号:sql :: mysql :: get_driver_instance(void) - Unresolved symbol: sql::mysql::get_driver_instance(void) MySQL 连接器/C++:从全局构造调用时 get_driver_instance() 崩溃 - MySQL Connector/C++: get_driver_instance() crashes when called from global construct C ++ / mysql连接器 - 对get_driver_instance的未定义引用 - 已经尝试过简单的东西 - C++ / mysql Connector - undefined reference to get_driver_instance - already tried the easy stuff MySQL Connector C ++无法解析的外部符号 - MySQL Connector C++ Unresolved External Symbol C ++ SQL连接“ get_driver_instance(); 未定义”错误 - c++ sql connection “get_driver_instance(); is undefined ” error 链接器错误与get_driver_instance()MySQL C ++ VS2010 - Linker error with get_driver_instance() MySQL C++ VS2010 mysql-connector-c ++-&#39;get_driver_instance&#39;不是&#39;sql :: mysql&#39;的成员 - mysql-connector-c++ - ‘get_driver_instance’ is not a member of ‘sql::mysql’ sql :: mysql :: get_driver_instance()找不到符号 - sql::mysql::get_driver_instance() Symbol not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM