【问题标题】:MySQL Connector C++ Unresolved External SymbolMySQL 连接器 C++ 未解析的外部符号
【发布时间】:2017-03-27 01:43:47
【问题描述】:

我正在 VS 2013 社区版中开发一个项目。它使用 MySQL 连接器 C++。这是一些代码:

数据库.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);
}

数据库.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】:
    1. 下载 MySQL 连接器 C++ 的源代码。
    2. 添加预处理器定义 CPPCONN_PUBLIC_FUNC=
    3. 配置 MySQL 连接器(您可能需要下载 CMake)
    4. 构建 MySQL 连接器。

    记得将预处理器定义 CPPCONN_PUBLIC_FUNC= 添加到所有使用 MySQL 连接器的文件中。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      • 2012-11-19
      • 1970-01-01
      相关资源
      最近更新 更多