J'écris une bibliothèque, qui est dynamiquement chargée dans mon application principale avec dlsym. J'ai les fichiers suivants:Pourquoi une erreur de recherche de symbole apparaît-elle?
library.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();
}
library.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();
}
}
affaires/BCGateway.h
#include <igateway.h>
class BCGateway: public IGateway {
public:
static IGateway* instance();
protected:
BCGateway();
private:
static IGateway* instance_;
};
affaires/BCGateway.cpp
#include "BCGateway.h"
IGateway* BCGateway::instance_ = NULL;
IGateway* BCGateway::instance(){
return instance_ ? instance_ : (instance_ = new BCGateway);
}
Je peux me connecter à la bibliothèque et charger avec succès l'instance de bibliothèque. Mais quand je l'appelle Library-> getGateway() dans ma principale application que je reçois l'erreur suivante:
symbol lookup error: ./gateways/libSwisscomXtraZone.so: undefined symbol: _ZN9BCGateway8instanceEv
Pouvez-vous s'il vous plaît me donner un indice, comment je peux résoudre ce problème? Je suis coincé.
Merci.
Ecrit mon dernier commentaire, j'ai vu, que j'ai juste oublié d'ajouter le BCGateway.h et BCGateway.cpp à mon fichier de projet, à partir duquel le makefile est généré. Donc, cette classe n'a en effet pas été déclarée dans ma bibliothèque. Depuis que je suis très nouveau pour les bibliothèques C++, j'ai pensé que c'est un problème avec la déclaration de la bibliothèque ou plus. Merci beaucoup pour votre aide. –