2013-07-24 37 views
2


所以這是我的問題。我正在Firebreath編寫Web瀏覽器插件。取決於客戶端請求,插件必須連接到不同的數據庫(Firebird,MS SQL,My SQL等)。所以我創建類來管理連接到正確的數據庫。要連接到Firebird,我試圖使用IBPP。我設法在簡單的測試項目中使用IBPP連接到FB。但是現在當我做更復雜的事情時,我得到了這個奇怪的鏈接器錯誤LNK2019。

確切的錯誤信息是:在Firebreath項目中使用IBPP時出現LNK2019錯誤

Error 2 error LNK2019: unresolved external symbol "class IBPP::Ptr<class IBPP::IDatabase> 
__cdecl IBPP::DatabaseFactory(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > 
const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > 
const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > 
const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > 
const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > 
const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > 
const &,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]@[email protected]@[email protected]@[email protected]) 
referenced in function "class IBPP::Ptr<class IBPP::IDatabase> 
__cdecl IBPP::DatabaseFactory(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > 
const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > 
const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > 
const &,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]@[email protected]@[email protected]@[email protected]) 
C:\ff-extensions\F4U\build\projects\F4UConv\Connections.obj F4UConv 



代碼爲我的連接看起來是這樣的:

#ifndef Connections_h 
#define Connections_h 

#include <cstdarg> 
#include <string> 

#include "ibpp\ibpp.h" 
#include "..\Logger\Logger.h" 

using namespace std; 

namespace Connections{ 

    class Connection { 
     public: 
      void set_logger(Logger::Logger *logger); 

      virtual bool setup_connection(string machine, string db_path, string login, string passwd)=0; 
      virtual bool connect()=0; 
      virtual bool disconnect()=0; 

      virtual bool setup_statement(string sql_statement, const char *fmt, ...)=0; 

      template <class Statement> 
      Statement execute_statement(); 

     protected: 
      string machine; 
      string db_path; 
      string login; 
      string passwd; 
      Logger::Logger *logger; 

    }; 

    class FB_Connection : public Connection { 
     public: 
      ~FB_Connection(); 

      bool setup_connection(string machine, string db_path, string login, string passwd); 
      bool connect(); 
      bool disconnect(); 

      bool setup_statement(string sql_statement, const char *fmt, ...); 

      template <class Statement> 
      Statement execute_statement(); 

     private: 
      IBPP::Database db; 
    }; 
}; 

#endif Connections_h 



#include "Connections.h" 

namespace Connections{ 

    void Connection::set_logger(Logger::Logger *logger){ 
     this->logger = logger; 
    } 

    FB_Connection::~FB_Connection(){ 
     if(this->db->Connected()){ 
      this->disconnect(); 
     } 
     db->Drop(); 
    } 

    bool FB_Connection::setup_connection(string machine, string db_path, string login, string passwd){ 
     this->machine = machine; 
     this->db_path = db_path; 
     this->login = login; 
     this->passwd = passwd; 

     try{ 
      this->db = IBPP::DatabaseFactory(this->machine, this->db_path, this->login, this->passwd); 

      this->db->Create(3); 
     }catch(IBPP::Exception& e){ 
      if(logger != nullptr){ 
       this->logger->log(Logger::LogMsgValue[Logger::E_LOGMSG_000002]); 
       this->logger->log(Logger::LEVEL_ERROR, e.ErrorMessage()); 
      } 
      return false; 
     } 

     return true; 
    } 

    bool FB_Connection::connect(){ 
     return true; 
    } 

    bool FB_Connection::disconnect(){ 
     return true; 
    } 

    bool FB_Connection::setup_statement(string sql_statement, const char *fmt, ...){ 
     return true; 
    } 

    template <class Statement> 
    Statement FB_Connection::execute_statement(){ 
     return this; 
    } 
} 



我google搜索了兩天,仍然不知道有什麼問題。我明白LNK2019錯誤的含義,但不知道爲什麼會出現這種情況。
生成此錯誤的行是:

this->db = IBPP::DatabaseFactory(this->machine, this->db_path, this->login, this->passwd); 

誰能告訴我有什麼不對?
哦,我正在使用Visual Studio 2012 Express。

回答

0

您試圖訪問該方法在你還沒有在連接namespace提供的定義來源,即

這種方法:

DatabaseFactory(this->machine, this->db_path, this->login, this->passwd); 

在提供一個定義它連接namespace

在源文件中寫入using namespace connections;

+0

並非如此。 DatabaseFactory是ibpp.h庫中名稱空間IBPP中定義的一種方法。 –

+0

然後,您應該在源文件中包含ibpp.h。爲什麼包含兩個名稱空間定義......一個在你的頭文件中,另一個在你的源文件中? – 0decimal0

+0

它包含在頭文件Connections.h中,所以它也在源文件中Connections.cpp –

相關問題