Link error: QMetaObject with cmake when compiling VTK example



  • Hello,
    i am trying to compile a Qt (Qt5.8) / VTK (8.0.0) example from here.

    I am using cmake and i have
    set(CMAKE_AUTOMOC ON)

    However i get a linking error with QMetaObject.

    Error:

    RenderWindowUIMultipleInheritance.cxx.obj:-1: error: LNK2001: unresolved external symbol "public: static struct QMetaObject const QVTKWidget::staticMetaObject" (?staticMetaObject@QVTKWidget@@2UQMetaObject@@B)
    RenderWindowUIMultipleInheritanceDriver.cxx.obj:-1: error: LNK2001: unresolved external symbol "public: static struct QMetaObject const QVTKWidget::staticMetaObject" (?staticMetaObject@QVTKWidget@@2UQMetaObject@@B)
    moc_compilation.cpp.obj:-1: error: LNK2001: unresolved external symbol "public: static struct QMetaObject const QVTKWidget::staticMetaObject" (?staticMetaObject@QVTKWidget@@2UQMetaObject@@B)
    

    Here is the CMakeLists.txt i use for the project

    cmake_minimum_required(VERSION 2.8)
    
    if(POLICY CMP0020)
      cmake_policy(SET CMP0020 NEW)
    endif()
    
    PROJECT(RenderWindowUIMultipleInheritance)
    
    find_package(VTK REQUIRED)
    include(${VTK_USE_FILE})
    
    # Instruct CMake to run moc automatically when needed.
    set(CMAKE_AUTOMOC ON)
    find_package(Qt5Widgets REQUIRED QUIET)
    
    include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
    
    file(GLOB UI_FILES *.ui)
    file(GLOB QT_WRAP *.h)
    file(GLOB CXX_FILES *.cxx)
    
    qt5_wrap_ui(UISrcs ${UI_FILES} )
    # CMAKE_AUTOMOC in ON so the MOC headers will be automatically wrapped.
    add_executable(RenderWindowUIMultipleInheritance MACOSX_BUNDLE
    ${CXX_FILES} ${UISrcs} ${QT_WRAP})
    qt5_use_modules(RenderWindowUIMultipleInheritance Core Gui)
    target_link_libraries(RenderWindowUIMultipleInheritance ${VTK_LIBRARIES})
    

    any ideas where the problem is?



  • Found the error myself.
    In the include dir there still was the file vtkGUISupportQtModule.h from the vtk-build included which defines

    VTKGUISUPPORTQT_EXPORT __declspec(dllexport)
    

    now its working



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.