I have a main program that, in the course of its work, loads a dynamic library, imports an instance of a class from there, and executes its method. The main program has a Test class and two files Test.h Test.cpp.
Test.h:
class Test {
public:
virtual void work() = 0;
}
class Test2 : public Test {
public:
void work() override;
virtual void test() = 0;
}
test.cpp:
void Test2::work(){
/*do something*/
}
Accordingly, this code is compiled in the main program. To create a dynamic library (.so/.dll), only the Test.h file is provided. Then the code of the library itself looks like this: lib.cpp:
#include "Test.h"
#include <iostream>
class Test3 : public Test2 {
public:
void test() override {
std::cout<<"I'm test 3"<<std::endl;
}
}
extern "C" BOOST_SYMBOL_EXPORT Test3 plugin;
For linux, everything builds without problems and subsequently this .so library works correctly, but for .dll on Windows it gives an error: "undefined reference to `vtable' for Test2". That is, it requires me to provide an implementation of the virtual function work (). Is there any way to get around this? I use regular CMake to build. cmake.txt:
add_library(lib SHARED Test.h lib.cpp)