MySQL Connector C ++未解析的外部符号

问题描述 投票:0回答:1

我正在开发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
c++ mysql visual-studio visual-c++ visual-studio-2013
1个回答
0
投票
  1. 下载MySQL Connector C ++的源代码。
  2. 添加预处理器定义CPPCONN_PUBLIC_FUNC=
  3. 配置MySQL连接器(您可能需要下载CMake)
  4. 构建MySQL连接器。

请记住将预处理器定义CPPCONN_PUBLIC_FUNC=添加到使用MySQL Connector的所有文件中。

您还需要下载MySQL源代码并构建它。

重建源代码将确保与MySQL服务器和连接器的编译器和平台兼容。

© www.soinside.com 2019 - 2024. All rights reserved.