0

我尝试使用以下代码在运行时加载 *.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链接的问题,但我不知道如何解决。

4

1 回答 1

0

好的,它有效。我需要TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${VTK_LIBRARIES})。所以lib将被加载

于 2013-05-16T16:05:34.440 回答