undefined reference to 'QVTKWidget::QVTKWidget'

564 views Asked by At

The env is VTK-8.0 ITK-5.2 QT-5.12

This error occurs when I compile this cmake file:

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})

And the error is:

 undefined reference to 'QVTKWidget::QVTKWidget' in ui.mainwindow.h:xxx

There is no LINK errors and any include fault, just can't detect this variable. I'm struggling in it all day:( But when I compile the example in VTK/Examples, nothing fails. The example CMakeLists is:

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})

I can't find there is any difference between them. So is there any probability that the code resulting in this error?

1

There are 1 answers

0
Pablo Iñigo Blasco On

You have to link your program to the library vtkGUISupportQt-7.1

In my case, I am in ubuntu 20.04 and that library is located in /usr/lib/x86_64-linux-gnu/libvtkGUISupportQt-7.1.so

you can get it installing the apt package: libvtk7-qt-dev

apt-get install libvtk7-qt-dev