2016-11-13 41 views
0

私はVS 2013 Community Editionでプロジェクトを進めています。 MySQL Connector C++を使用します。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 &)" ([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 Connector C++のソース。
  2. プリプロセッサ定義CPPCONN_PUBLIC_FUNC=
  3. 設定のMySQLコネクタを追加MySQLのコネクタを構築
  4. を(あなたはCMakeのをダウンロードする必要があります)。

のMySQL Connectorを使用するすべてのファイルにプリプロセッサ定義CPPCONN_PUBLIC_FUNC=を追加することを忘れないでください。

また、MySQLソースをダウンロードしてビルドする必要もあります。

ソースを再構築すると、コンパイラとプラットフォームとMySQLサーバとコネクタとの互換性が保証されます。

関連する問題