2016-11-13 80 views
0

我正在開發VS 2013社區版的項目。它使用MySQL Connector C++。下面是一些代碼:MySQL連接器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 &)" ([email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) 
1>Database.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::~SQLString(void)" ([email protected]@@[email protected]) 
1>C:\Users\averysumner\Desktop\lurebornserver\Source\Release\LURServer.exe : fatal error LNK1120: 3 unresolved externals 

回答

0
  1. 下載MySQL連接器C++的源代碼。
  2. 添加預處理器定義CPPCONN_PUBLIC_FUNC=
  3. 配置MySQL連接器(您可能需要下載CMake的)
  4. 構建MySQL連接。

記住的預處理器定義CPPCONN_PUBLIC_FUNC=添加到使用MySQL連接器中的所有文件。

您還需要下載MySQL源代碼並構建它。

重建源代碼將確保您的編譯器和平臺與MySQL服務器和連接器的兼容性。