C ++对“ get_driver_instance”的未定义引用

问题描述

我正在Linux Mint上运行以下代码

#include <iostream>
#include <memory>
#include "Logger.h"
#include "Config.h"
#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() {
    shared_ptr<Config> config = make_shared<Config>("WorldServer");
    string def = "nothing there.";
    Logger::Log("Authserver Conn: " + config->GetConfigValue("LoginDatabaseInfo",def));

    try {
        sql::Driver *driver;
        sql::Connection *con;
        sql::Statement *stmt;
        sql::ResultSet *res;

        const string host = config->GetConfigValue("LoginDatabase.MysqL.IP",def);
        const string MysqLUser = config->GetConfigValue("LoginDatabase.MysqL.IP",def);
        const string MysqLPassword = config->GetConfigValue("LoginDatabase.MysqL.IP",def);
        const string MysqLDatabase = config->GetConfigValue("LoginDatabase.MysqL.IP",def);

        /* Create a connection */
        driver = get_driver_instance();
        con = driver->connect(host,MysqLUser,MysqLPassword);
        /* Connect to the MysqL test database */
        con->setSchema(MysqLPassword);

        stmt = con->createStatement();
        res = stmt->executeQuery("SELECT * FROM accounts");
        while (res->next()) {
            cout << "\t... MysqL replies: ";
            /* Access column data by alias or column name */
            cout << res->getString("warTag") << 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;
    }
}

当我尝试构建它时,出现以下错误

undefined reference to `get_driver_instance`

我也已经安装了这个

sudo apt-get install  libMysqLcppconn-dev

此问题可能是什么原因,我该如何解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)