Estoy escribiendo una biblioteca, que se carga dinámicamente en mi aplicación principal con dlsym. I tienen los siguientes archivos:¿Por qué recibo un error de búsqueda de símbolos?
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();
}
}
negocio/BCGateway.h
#include <igateway.h>
class BCGateway: public IGateway {
public:
static IGateway* instance();
protected:
BCGateway();
private:
static IGateway* instance_;
};
negocio/BCGateway.cpp
#include "BCGateway.h"
IGateway* BCGateway::instance_ = NULL;
IGateway* BCGateway::instance(){
return instance_ ? instance_ : (instance_ = new BCGateway);
}
Puedo conectarme a la biblioteca y cargar correctamente la instancia de biblioteca. Pero cuando llamo biblioteca-> getGateway() en mi principal aplicación me sale el siguiente error:
symbol lookup error: ./gateways/libSwisscomXtraZone.so: undefined symbol: _ZN9BCGateway8instanceEv
¿Me podría dar una pista, cómo puedo resolver esto? Estoy atascado.
Gracias.
Escribí mi último comentario, vi que acababa de olvidar agregar BCGateway.hy BCGateway.cpp a mi archivo de proyecto, del cual se genera el archivo MAKE. Entonces esta clase no fue declarada en mi biblioteca. Como soy muy nuevo en las bibliotecas de C++, pensé que era un problema con la declaración de la biblioteca o algo así. Muchas gracias por tu ayuda. –