【问题标题】:LNK2019 error while using IBPP in Firebreath project在 Firebreath 项目中使用 IBPP 时出现 LNK2019 错误
【发布时间】:2013-07-24 22:19:01
【问题描述】:


所以这是我的问题。我正在 Firebreath 中编写网络浏览器插件。插件必须根据客户端请求连接到不同的数据库(Firebird、MS SQL、My SQL 等)。所以我正在创建类来管理与正确数据库的连接。要连接到 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



我的连接代码如下所示:
标题

#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;
    }
}



我在谷歌上搜索了两天,仍然不知道是什么问题。我了解 LNK2019 错误的含义,但不知道为什么会出现这种情况。
产生此错误的行是:

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

谁能告诉我怎么了?
哦,我正在使用 Visual Studio 2012 Express。

【问题讨论】:

    标签: c++ firebird firebreath lnk2019


    【解决方案1】:

    您正在尝试访问未在连接namespace 中提供定义的源中的方法,即

    这个方法:

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

    在连接namespace中为其提供定义。

    在源文件中写入using namespace connections;

    【讨论】:

    • 不是这样的。 DatabaseFactory 是 ibpp.h 库中命名空间 IBPP 中定义的方法。
    • 那么你应该在源文件中包含 ibpp.h。为什么你要包含两个命名空间定义......一个在你的标题中,第二个在你的源代码中???
    • 它包含在头文件 Connections.h 中,因此它也在源文件 Connections.cpp 中
    • 源文件中的命名空间不是从头文件中重新定义命名空间或对该命名空间的第二个定义,它是一种正确的编码方式。当您使用命令“使用命名空间”时,它没有实现。虽然这也应该编译和工作。
    • @Michał 我不认为将 ibpp.h 包含在 connection.h 的定义中也包括在源代码中的 databasefactory 的定义......只需包含 connections.h ......那就是链接器无法解析名称。
    猜你喜欢
    • 2018-07-14
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-23
    • 1970-01-01
    相关资源
    最近更新 更多