简体   繁体   中英

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
  • Linked Connector/C++ static library
  • 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.

Configuration Properties / C/C++ / General / Additional Include Directories: C:\\boost; C:\\Program Files\\MySQL\\MySQL Connector C++ 1.1.9\\include

Configuration Properties / C/C++ / Preprocessor / Preprocessor Definicions: WIN32l; NDEBUG; _CONSOLE; CPPCONN_PUBLIC_FUNC=

Configuration Properties / Linker / General / Additional Library Directories: C:\\Program Files\\MySQL\\MySQL Connector C++ 1.1.9\\lib\\opt

Configuration Properties / Linker / Input / Additional Dependencies: 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. As I've checked in official downloads, binaries are for Visual studio 2013 - VC 12.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM