我尝试使用以下代码在运行时加载 *.so:
handle = dlopen(Path, RTLD_LAZY);
create = (FunctionEquationInterface* (*)())dlsym(handle, "CreateClass");
destroy = (void (*)(FunctionEquationInterface*))dlsym(handle, "DestroyClass");
FunctionEquationInterface
看起来像:
class LocalFunctionImplementation : public FunctionEquationInterface
{
public:
virtual int CreatePolynom(vtkUnstructuredGrid *input, vtkDataArray *coefficientArray);
virtual double Evaluate(Point *point);
};
extern "C" LocalFunctionImplementation* CreateClass();
extern "C" void DestroyClass(LocalFunctionImplementation*);
我用 cmake 构建库
add_library(${PROJECT_NAME} SHARED LocalFunctionImplementation.cpp)
问题是lib不会被加载。handle
仍然是NULL 。
我认为这是VTK链接的问题,但我不知道如何解决。