环境是 VTK-8.0 ITK-5.2 QT-5.12
当我编译这个 cmake 文件时发生这个错误:
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(QtDICOMViewer)
find_package(VTK REQUIRED)
#find_package(VTK COMPONENTS
# vtkCommonCore
# vtkFiltersSources
# vtkGUISupportQt
# vtkIOImage
# vtkInteractionImage
# vtkFiltersCore
# vtkInfovisCore
# vtkInteractionStyle
# vtkViewsQt
# vtkCommonDataModel
# vtkCommonExecutionModel
# vtkRenderingCore
# vtkRenderingFreeType
# vtkRenderingOpenGL2
# )
include(${VTK_USE_FILE})
if("${VTK_QT_VERSION}" STREQUAL "")
message(FATAL_ERROR "VTK was not built with Qt")
endif()
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
# Set your files and resources here
set( Srcs main.cpp mainwindow.cpp)
set( Hdrs mainwindow.h )
set( MOC_Hdrs mainwindow.h )
set( UIs mainwindow.ui )
set( QRCs images.qrc )
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Widgets REQUIRED QUIET)
qt5_wrap_ui(UI_Srcs ${UIs})
qt5_add_resources(QRC_Srcs ${QRCs} )
source_group("Resources" FILES
${UIs}
${QRCs}
${EXE_ICON} # Not present
)
source_group("Generated" FILES
${UI_Srcs}
${MOC_Srcs}
${QRC_Srcs}
)
include_directories(/usr/include/gdcm-2.6)
# CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
add_executable(QtDICOMViewer MACOSX_BUNDLE ${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs} ${QRC_Srcs})
qt5_use_modules(QtDICOMViewer Core Gui Widgets)
target_link_libraries(QtDICOMViewer ${VTK_LIBRARIES} ${ITK_LIBRARIES})
错误是:
undefined reference to 'QVTKWidget::QVTKWidget' in ui.mainwindow.h:xxx
没有 LINK 错误和任何包含错误,只是无法检测到这个变量。我整天都在苦苦挣扎:(但是当我在 VTK/Examples 中编译示例时,没有任何失败。示例 CMakeLists 是:
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(QtVTKRenderWindows)
find_package(VTK COMPONENTS
vtkCommonCore
vtkFiltersSources
vtkGUISupportQt
vtkIOImage
vtkInteractionImage
vtkFiltersCore
vtkInfovisCore
vtkInteractionStyle
vtkViewsQt
)
include(${VTK_USE_FILE})
if("${VTK_QT_VERSION}" STREQUAL "")
message(FATAL_ERROR "VTK was not built with Qt")
endif()
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
# Set your files and resources here
set( Srcs QtVTKRenderWindowsApp.cxx QtVTKRenderWindows.cxx)
set( Hdrs QtVTKRenderWindows.h)
set( MOC_Hdrs QtVTKRenderWindows.h)
#set( UIs QtVTKRenderWindows.ui )
set( QRCs Icons/icons.qrc )
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Widgets REQUIRED QUIET)
#qt5_wrap_ui(UI_Srcs ${UIs})
qt5_add_resources(QRC_Srcs ${QRCs} )
source_group("Resources" FILES
${UIs}
${QRCs}
${EXE_ICON} # Not present
)
source_group("Generated" FILES
${UI_Srcs}
${MOC_Srcs}
${QRC_Srcs}
)
# CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
add_executable(QtVTKRenderWindows MACOSX_BUNDLE ${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs} ${QRC_Srcs})
qt5_use_modules(QtVTKRenderWindows Core Gui Widgets)
target_link_libraries(QtVTKRenderWindows ${VTK_LIBRARIES})
我找不到它们之间有什么区别。那么代码是否有可能导致此错误?