0

I'm having the famous linking error when trying to combine Qt and VTK. I've done all the steps of installing Qt with VTK correctly so I don't know what could possibly be wrong.

I'm using windows 8 with Qt5 and VTK 6.3 on visual studio.

Here is the error I get:

Drawing.obj : error LNK2019: symbole externe non résolu "__declspec(dllimport) public: __thiscall QVTKWidget::QVTKWidget(class QWidget *,class QFlags<enum Qt::WindowType>)" (__imp_??0QVTKWidget@@QAE@PAVQWidget@@V?$QFlags@W4WindowType@Qt@@@@@Z) référencé dans la fonction "public: __thiscall Drawing::Drawing(void)" (??0Drawing@@QAE@XZ)
1>Drawing.obj : error LNK2019: symbole externe non résolu "__declspec(dllimport) public: virtual __thiscall QVTKWidget::~QVTKWidget(void)" (__imp_??1QVTKWidget@@UAE@XZ) référencé dans la fonction "public: __thiscall Drawing::~Drawing(void)" (??1Drawing@@QAE@XZ)

And here is the code I use:

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QVtk w;
    w.show();
    //start();
    return a.exec();
}

I followed everything that was written here: Combining Qt 5.4.1 with vtk 6.2.0 (using CMake GUI 3.2.1) on windows but somehow I get this error.

Also, I've added: $(QTDIR)\lib to my additional libraries $(QTDIR)\include to my "other include directories" and the followings to my additional dependencies.

qtmaind.lib
C:\Users\Lonni\VTK\Build2012Qt\lib\MinSizeRel\QVTKWidgetPlugin.lib
Qt5Cored.lib
Qt5Guid.lib
Qt5Locationd.lib
Qt5Multimediad.lib
Qt5MultimediaWidgetsd.lib
Qt5Testd.lib
Qt5AxContainerd.lib
Qt5AxBased.lib
Qt5OpenGLd.lib
opengl32.lib
glu32.lib
Qt5Sensorsd.lib
Qt5Svgd.lib
Qt5Widgetsd.lib

EDIT:

I did not use CMake for the project as I have issues when using Cmake even with the small example provided on the wiki which gives the following error with the following CMakeLists.txt. NB: I use Visual Studio as a generator.

CMakeLists:

cmake_minimum_required(VERSION 2.8)

if(POLICY CMP0020)
  cmake_policy(SET CMP0020 NEW)
endif()

PROJECT(RenderWindowNoUiFile)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
  # Instruct CMake to run moc automatically when needed.
  set(CMAKE_AUTOMOC ON)
  find_package(Qt5Widgets REQUIRED QUIET)
else()
  find_package(Qt4 REQUIRED)
  include(${QT_USE_FILE})
endif()

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)

if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
  qt5_wrap_ui(UISrcs ${UI_FILES} )
  # CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
  add_executable(RenderWindowNoUiFile MACOSX_BUNDLE
    ${CXX_FILES} ${UISrcs} ${QT_WRAP})
  qt5_use_modules(RenderWindowNoUiFile Core Gui)
  target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES})
else()
  QT4_WRAP_UI(UISrcs ${UI_FILES})
  QT4_WRAP_CPP(MOCSrcs ${QT_WRAP})
  add_executable(RenderWindowNoUiFile MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${MOCSrcs})

  if(VTK_LIBRARIES)
    if(${VTK_VERSION} VERSION_LESS "6")
      target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES} QVTK)
    else()
      target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES})
    endif()
  else()
    target_link_libraries(RenderWindowNoUiFile vtkHybrid QVTK vtkViews ${QT_LIBRARIES})
  endif()
endif()

Error: CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.2/Modules/FindQt4.cmake:1326 (message): Found unsuitable Qt version "" from NOTFOUND, this code requires Qt 4.x Call Stack (most recent call first): CMakeLists.txt:18 (find_package)

Community
  • 1
  • 1
LBes
  • 3,366
  • 1
  • 32
  • 66
  • What does your CMakeList look like? – asdfasdf Jul 02 '15 at 19:39
  • Can you run this example project? http://www.vtk.org/Wiki/VTK/Examples/Cxx/Qt/RenderWindowNoUiFile – asdfasdf Jul 02 '15 at 19:49
  • No I can't cause the CMakeList is giving me weird errors. It's trying to get Qt4 even though I have Qt5 – LBes Jul 03 '15 at 08:47
  • Still stuck here. There is no way of running even the simple example you've given (see edit) and I still get the linking error in visual studio. – LBes Jul 07 '15 at 09:58
  • 1
    The right thing to do is almost never to not use CMake. You need to set QT_QMAKE_EXECUTABLE to the qmake binary of the version of Qt you want to use for CMake to use the version you want it to use. – David Doria Jul 07 '15 at 13:42
  • I have tried that but I still get the same error. The QT_QMAKE_EXECUTABLE was in the advanced tab so I didn't see it at first but now I have it and it still doesn't work – LBes Jul 07 '15 at 14:24
  • In your CMake example, enable Advanced (in the CMake GUI) and set VTK_QT_VERSION to 5. I think that's the error message you're getting. – Blito Jul 11 '15 at 01:50
  • I've tried that already and it sill doesn't work – LBes Jul 11 '15 at 14:20

0 Answers0