这就是我的问题。我正在Firebreath中编写web浏览器插件。插件必须根据客户端请求连接到不同的数据库(Firebird、MS SQL、My SQL等)。所以我正在创建一个类来管理到右DB的连接。为了连接到火鸟,我正在尝试使用IBPP。我设法在简单的测试项目中使用IBPP连接到FB。但现在,当我做一些更复杂的事情时,我遇到了这个奇怪的链接器错误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 &)
" (?DatabaseFactory@IBPP@@YA?AV?$Ptr@VIDatabase@IBPP@@@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@000000@Z)
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 &)"
(?DatabaseFactory@IBPP@@YA?AV?$Ptr@VIDatabase@IBPP@@@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@000@Z)
C:ff-extensionsF4UbuildprojectsF4UConvConnections.obj F4UConv
我的连接代码如下:
标题
#ifndef Connections_h
#define Connections_h
#include <cstdarg>
#include <string>
#include "ibppibpp.h"
#include "..LoggerLogger.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;
}
}
我在谷歌上搜索了两天,仍然不知道出了什么问题。我理解LNK2019错误的含义,但不知道为什么会在这种情况下发生
生成此错误的行是:
this->db = IBPP::DatabaseFactory(this->machine, this->db_path, this->login, this->passwd);
有人能告诉我怎么了吗
哦,我正在使用Visual Studio 2012学习版。
您正试图访问源中的方法,而您尚未在连接namespace
中提供该方法的定义,即
这种方法:
DatabaseFactory(this->machine, this->db_path, this->login, this->passwd);
在连接namespace
中为其提供定义。
在源文件中写入using namespace connections;
。