我正在开发VS 2013 Community Edition中的一个项目。它使用MySQL Connector C ++。这是一些代码:
Database.cpp:
#include "Database.h"
#include "Common.h"
#include <iostream>
//This function is used to connect to the MySQL database
void Database::Connect()
{
Config::loadConfig("config.ini");
MySQLSettings settings = Config::getMySQLSettings();
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
//Creates a connection to your MySQL server
driver = get_driver_instance();
con = driver->connect("tcp://" + settings.host + ":3306", settings.username, settings.password);
//Connect to LUR database
con->setSchema(settings.database);
}
Database.h:
#pragma once
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
class Database
{
public:
static void Connect(); //Database connection function
};
使用该代码,我收到了以下错误:
1>Database.obj : error LNK2001: unresolved external symbol __imp__get_driver_instance
1>Database.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0SQLString@sql@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>Database.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::~SQLString(void)" (__imp_??1SQLString@sql@@QAE@XZ)
1>C:\Users\anon\Desktop\lurebornserver\Source\Release\LURServer.exe : fatal error LNK1120: 3 unresolved externals
答案 0 :(得分:0)
CPPCONN_PUBLIC_FUNC=
请记住将预处理程序定义 CPPCONN_PUBLIC_FUNC=
添加到使用MySQL Connector的所有文件中。
您还需要下载MySQL源代码并构建它。
重建源代码将确保与MySQL服务器和连接器的编译器和平台兼容。