gpt4 book ai didi

c++ - 为什么会出现符号查找错误?

转载 作者:可可西里 更新时间:2023-11-01 18:27:46 27 4
gpt4 key购买 nike

我正在编写一个库,它使用 dlsym 动态加载到我的主应用程序中。我有以下文件:

库.h

#include <ilibrary.h>
#include <igateway.h>

class LibraryImpl;

class Library: public ILibrary {
public:
static ILibrary* instance();

IGateway* getGateway() const;

protected:
Library();
virtual ~Library();

private:
static ILibrary* instance_;
LibraryImpl* library_;
};

extern "C" {
IMPORT_EXPORT ILibrary* getLibrary();
}

库.cpp

#include "library.h"

#include "business/BCGateway.h"


class LibraryImpl {
public:
IGateway* getGateway();
};

IGateway* LibraryImpl::getGateway() {
return BCGateway::instance();
}



ILibrary* Library::instance_ = NULL;
ILibrary* Library::instance() {
return instance_ ? instance_ : (instance_ = new Library);
}

Library::Library() {
library_ = new LibraryImpl();
}

Library::~Library() {
delete library_;
}

IGateway* Library::getGateway() const {
return library_->getGateway();
}


extern "C" {
IMPORT_EXPORT
ILibrary* getLibrary(){
return Library::instance();
}
}

business/BCGateway.h

#include <igateway.h>

class BCGateway: public IGateway {
public:
static IGateway* instance();

protected:
BCGateway();

private:
static IGateway* instance_;
};

business/BCGateway.cpp

#include "BCGateway.h"

IGateway* BCGateway::instance_ = NULL;
IGateway* BCGateway::instance(){
return instance_ ? instance_ : (instance_ = new BCGateway);
}

我可以连接到库并成功加载库实例。但是,当我在我的主应用程序中调用 library->getGateway() 时,出现以下错误:

symbol lookup error: ./gateways/libSwisscomXtraZone.so: undefined symbol: _ZN9BCGateway8instanceEv

你能给我一个提示,我该如何解决这个问题?我卡住了。

谢谢。

最佳答案

我把错误通过c++filt,它说错乱的名字代表

BCGateway::instance()

这表明您在某处调用了 BCGateway::instance() 而忘记链接到 BCGateway.o 或者您甚至忘记定义 BCGateway::instance ()

关于c++ - 为什么会出现符号查找错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1118905/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com