C++ 在Firebreath项目中使用IBPP时发生LNK2019错误

C++ 在Firebreath项目中使用IBPP时发生LNK2019错误,c++,firebird,firebreath,lnk2019,C++,Firebird,Firebreath,Lnk2019,这就是我的问题。我正在用Firebreath编写web浏览器插件。插件必须根据客户端请求连接到不同的数据库(Firebird、MS SQL、My SQL等)。所以我创建了一个类来管理到右DB的连接。要连接到Firebird,我正在尝试使用IBPP。在这个简单的测试项目中,我使用IBPP连接到了FB。但现在当我做更复杂的事情时,我有一个奇怪的链接器错误LNK2019。 确切的错误消息是: Error 2 error LNK2019: unresolved external symbol


这就是我的问题。我正在用Firebreath编写web浏览器插件。插件必须根据客户端请求连接到不同的数据库(Firebird、MS SQL、My SQL等)。所以我创建了一个类来管理到右DB的连接。要连接到Firebird,我正在尝试使用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-extensions\F4U\build\projects\F4UConv\Connections.obj F4UConv
谁能告诉我出了什么问题吗?

哦,我正在使用Visual Studio 2012 Express。

您正在尝试访问源中的方法,但尚未在连接
命名空间中为其提供定义,即

此方法:

DatabaseFactory(this->machine, this->db_path, this->login, this->passwd);
在连接
命名空间
中为其提供定义


使用名称空间连接编写

不是这样的。DatabaseFactory是在IBPP.h库的名称空间IBPP中定义的方法。那么您应该在源文件中包含IBPP.h。为什么要包含两个名称空间定义。。。一个在头文件中,另一个在源文件中???它包含在头文件连接中。h所以它也包含在源文件连接中。cpp源文件中的名称空间不是从头文件或该名称空间的第二个定义中重新定义名称空间,它是一种正确的编码方式。当您使用命令“usingnamespace”而不是实现它时,可以使用该命令。虽然这应该也可以编译和工作。@Michał我认为在
connection.h的定义中包含ibpp.h并不意味着在源代码中包含databasefactory的定义。。。只需包括
连接.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;
    }
}
this->db = IBPP::DatabaseFactory(this->machine, this->db_path, this->login, this->passwd);
DatabaseFactory(this->machine, this->db_path, this->login, this->passwd);