C++ 在运行时动态加载库don';行不通

C++ 在运行时动态加载库don';行不通,c++,vtk,C++,Vtk,我尝试在运行时使用以下代码加载*.so: handle = dlopen(Path, RTLD_LAZY); create = (FunctionEquationInterface* (*)())dlsym(handle, "CreateClass"); destroy = (void (*)(FunctionEquationInterface*))dlsym(handle, "DestroyClass"); FunctionEquationInterface如下所示: class Local

我尝试在运行时使用以下代码加载*.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构建lib

add_library(${PROJECT_NAME} SHARED LocalFunctionImplementation.cpp)
问题是不会加载库。
句柄
仍然为空


我认为VTK的链接有问题,但我不知道如何解决这个问题。

好的,它可以工作。我需要
目标链接库(${PROJECT\u NAME}${VTK\u LIBRARIES})
。因此,将加载库

您使用的是什么
路径
呢?它是一个
char*
变量我的意思是,它的内容是什么?根据路径的确切内容,系统可能无法找到您的库。请看(不知道这是否是您的实际问题,但乍一看我没有发现任何其他错误)它需要更正到的文件路径。因此我检查了它。