1
lib의 클래스에서 포인터로 메인 클래스의 멤버 함수에 액세스하고 싶습니다.정의되지 않은 심볼, 포인터가있는 멤버 함수에 대한 액세스 C++
내 메인 클래스의 public 변수에 액세스 할 수 있습니다. 내가 멤버 함수 (공공)에 액세스하려고 할 때, 나는이 오류가 :
./Panda: symbol lookup error: libkoala.so: undefined symbol: _ZNK5Panda6getLOLEv
난 정말 모르겠어요 왜, 어쩌면 내가 ...
C++의 개념을 이해하지 않아도내 주요 클래스 :
class Panda
{
protected:
IAssistant* (*external_creator)();
IAssistant* lib;
void* dlhandle;
int lol;
public:
int hello;
Panda();
~Panda();
int getLOL() const;
};
Panda::Panda()
{
if ((dlhandle = dlopen("libkoala.so", RTLD_LAZY)) == NULL)
exit(-1);
if ((external_creator = reinterpret_cast<IAssistant* (*)()>(dlsym(dlhandle, "create_assistant"))) == NULL)
exit(-1);
lib = external_creator();
lol = 69;
hello = 42;
lib->do_something(this);
}
Panda::~Panda(){
}
int Panda::getLOL() const
{
return lol;
}
인터페이스가 다음과 같습니다
class IAssistant
{
public:
virtual void do_something(Panda *) = 0;
};
그리고 내 lib 디렉토리에있는 클래스 :
class Koala : public IAssistant
{
public:
void do_something(Panda *);
};
void Koala::do_something(Panda * ptr)
{
std::cout << ptr->hello; <========= work perfectly
std::cout << ptr->getLOL(); <====== doesn't work
}
extern "C"
{
IAssistant* create_assistant()
{
return new Koala();
}
}
혹시 궁금한 점이 있습니까?
@Luchian 첫 번째 코드 단편 하단에 있습니다. – us2012
순환 의존성이있는 것처럼 보입니다 ... – Synxis
왜''Coreall :: do_something'에'virtual' 키워드를 넣었습니까? 왜냐하면'IAssistant'에서 그것을 오버라이드하고있는 이유는 무엇입니까? – mr5