CMake:依赖的新子类“未解析的外部符号”

时间:2015-08-31 15:15:16

标签: qt cmake vtk

我有一个子类化VTK类的问题,但我认为问题可以链接到任何类型的库。

我做了一个vtkInteractorStyleImage子类,只是重写了一个方法:

#ifndef dcmInteractorStyleImage_h
#define dcmInteractorStyleImage_h

#include "vtkInteractionStyleModule.h" // For export macro
#include "vtkInteractorStyleImage.h"

class VTKINTERACTIONSTYLE_EXPORT dcmInteractorStyle : public vtkInteractorStyleImage
{
public:
    static dcmInteractorStyle *New();
    vtkTypeMacro(dcmInteractorStyle, vtkInteractorStyleImage);

    virtual void OnLeftButtonDown();

    void PrintSelf(ostream& os, vtkIndent indent);
};    

#endif

问题是我在Qt课程中使用它。所以我将它包含在我的CMakeLists.txt(简化)中:

set(GENERIC_VIEW_CPP
     View/UI/dcminteractorstyle.cpp   # my new class
)

SET(GENERIC_VIEW_H
     View/UI/dcminteractorstyle.h     # my new class
)

add_library(generic ${GENERIC_VIEW_CPP} ${GENERIC_VIEW_H})
...
add_library(ui_qt ${UI_QT_CXX}
     ${UI_FORM_HEADERS} ${UI_RESOURCES_RCC}
     ${MODEL_WRAPPED_HEADERS}
     ${GENERIC_VIEW_CPP} ${GENERIC_VIEW_H} #necesary here?
)
qt5_use_modules(ui_qt Core Gui Widgets)
----------------------------------------------------------

# VTK
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

# ITK
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
  find_package(VTK REQUIRED)
  include(${VTK_USE_FILE})
else()
  find_package(ItkVtkGlue REQUIRED)
  include(${ItkVtkGlue_USE_FILE})
  set(Glue ItkVtkGlue)
endif()

------------------------------------------------
set_source_files_properties(${UI_RESOURCES_RCC} PROPERTIES GENERATED ON)
add_executable(UtilidadDICOM WIN32 main.cpp ${UI_RESOURCES_RCC})
target_link_libraries(UtilidadDICOM
    model
    ui_qt
    generic
    ${Glue}
    ${VTK_LIBRARIES}
    ${ITK_LIBRARIES}
)

尝试编译的错误:

  

ui_qt.lib(viewerwidget.cpp.obj): - 1:错误:LNK2019:未解决   外部符号“public:static class dcmInteractorStyle * __cdecl   dcmInteractorStyle :: New(void)“(?new @ dcmInteractorStyle @@ SAPAV1 @ XZ)   在函数“public:static class vtkSmartPointer __cdecl vtkSmartPointer :: New(void)”中引用   (?新@?$ @ vtkSmartPointer @@@@ VdcmInteractorStyle SA'AV1 @ XZ)

ui_qt是一个在CMake中声明的库,如上所示。

有什么想法吗?谢谢。

1 个答案:

答案 0 :(得分:0)

简短的回答是你的班级没有被联系。在将其链接到可执行文件之前尝试查看泛型中的值。在target_link_libraries之前做一条消息:

MESSAGE(${generic})

并查看generic.lib是否实际链接。