2

环境是 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})

我找不到它们之间有什么区别。那么代码是否有可能导致此错误?

4

1 回答 1

0

您必须将您的程序链接到库 vtkGUISupportQt-7.1

就我而言,我在 ubuntu 20.04 中,该库位于 /usr/lib/x86_64-linux-gnu/libvtkGUISupportQt-7.1.so

你可以让它安装 apt 包:libvtk7-qt-dev

apt-get 安装 libvtk7-qt-dev

于 2021-09-26T11:51:39.013 回答