2013-05-16 39 views
0

我嘗試在運行時加載一個*。所以用下面的代碼:負載動態地LIB不工作

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*); 

我建的lib與cmake

add_library(${PROJECT_NAME} SHARED LocalFunctionImplementation.cpp) 

問題是,lib將不會被加載。 handle仍然是NULL。

我認爲這是連接VTK的問題,但我不知道如何解決這個問題。

+0

你使用什麼'Path'? – syam

+0

這是一個char *變量 – shinpei

+0

我的意思是,它的內容是什麼?根據「路徑」的確切內容,系統可能無法找到您的庫。看到http://stackoverflow.com/a/16335841/2070725(不知道這是你的實際問題,但乍一看我沒有看到其他任何錯誤) – syam

回答

0

好吧,它的工作原理。我需要TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${VTK_LIBRARIES})。所以這個lib將被加載