未定义对“QVTKWidget::QVTKWidget”的引用
Posted
技术标签:
【中文标题】未定义对“QVTKWidget::QVTKWidget”的引用【英文标题】:undefined reference to 'QVTKWidget::QVTKWidget' 【发布时间】:2020-11-26 08:13:56 【问题描述】:环境是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)
我找不到它们之间的任何区别。那么代码有没有可能导致这个错误呢?
【问题讨论】:
【参考方案1】:你必须将你的程序链接到库 vtkGUISupportQt-7.1
就我而言,我在 ubuntu 20.04 中,该库位于 /usr/lib/x86_64-linux-gnu/libvtkGUISupportQt-7.1.so 中
你可以得到它安装apt包:libvtk7-qt-dev
apt-get install libvtk7-qt-dev
【讨论】:
以上是关于未定义对“QVTKWidget::QVTKWidget”的引用的主要内容,如果未能解决你的问题,请参考以下文章