0

I have installed QT6 and successfully build VTK 9.1. I have added the following environment variables:

%QTDIR%\bin
%QTDIR%\lib
%VTK_DIR%\bin

where QTDIR points to C:\Qt\6.2.3\msvc2019_64 and VTK_DIR points to C:\VTK where the VTK is installed after build. The VTK_DIR contains bin, include, and lib directories.

In the project.pro file, I have added the following:

QT += core gui opengl
...
INCLUDEPATH += $$(VTK_DIR)/include/vtk-9.1
LIBS += -LC:$$(VTK_DIR)/lib

I don't get any missing header file errors which means that QT Creator finds the header files. The project runs fine in QT Creator without adding OpenGL Widget to the form. But when I add OpenGL Widget to the form, it gives the following error:

17:16:06: Running steps for project VTKTest...
17:16:06: Configuration unchanged, skipping qmake step.
17:16:06: Starting: "C:\Qt\Tools\mingw900_64\bin\mingw32-make.exe" -j12
C:/Qt/6.2.3/mingw_64/bin/qmake.exe -o Makefile ../VTKTest/VTKTest.pro -spec win32-g++ CONFIG+=debug CONFIG+=qml_debug
C:/Qt/Tools/mingw900_64/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Work/Qt/Creator/build-VTKTest-Desktop_Qt_6_2_3_MinGW_64_bit-Debug'
g++ -Wl,-subsystem,windows -mthreads -o debug/VTKTest.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o  -LC:C:/VTK/lib C:/Qt/6.2.3/mingw_64/lib/libQt6OpenGL.a C:/Qt/6.2.3/mingw_64/lib/libQt6Widgets.a C:/Qt/6.2.3/mingw_64/lib/libQt6Gui.a C:/Qt/6.2.3/mingw_64/lib/libQt6Core.a -lmingw32 C:/Qt/6.2.3/mingw_64/lib/libQt6EntryPoint.a -lshell32  
C:/Qt/Tools/mingw900_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: debug/mainwindow.o: in function `Ui_MainWindow::setupUi(QMainWindow*)':
C:\Test\build-VTKTest-Desktop_Qt_6_2_3_MinGW_64_bit-Debug/./ui_mainwindow.h:33: undefined reference to `__imp__ZN22QVTKOpenGLStereoWidgetC1EP7QWidget6QFlagsIN2Qt10WindowTypeEE'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile.Debug:72: debug/VTKTest.exe] Error 1
mingw32-make[1]: Leaving directory 'C:/Test/build-VTKTest-Desktop_Qt_6_2_3_MinGW_64_bit-Debug'
mingw32-make: *** [Makefile:45: debug] Error 2
17:16:12: The process "C:\Qt\Tools\mingw900_64\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project VTKTest (kit: Desktop Qt 6.2.3 MinGW 64-bit)
When executing step "Make"
17:16:12: Elapsed time: 00:06.

I have also tried with LIBS += $$(VTK_DIR)/lib and LIBS += $$(VTK_DIR)/lib/*.lib, no joy.

In VS2019 I have installed the QT VS Tools which works fine. I also added all the VTK include, lib, and bin directories in project VC++ Directories section. Without adding OpenGL Widget to the form the project runs fine. But here too when I add OpenGL Widget to the form, it gives me the following build error:

Build started...
1>------ Build started: Project: VTKTest, Configuration: Debug x64 ------
1>Reading Qt configuration (C:/Qt/6.2.3/msvc2019_64/bin/qmake)
1>VTKTest.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QVTKOpenGLStereoWidget::QVTKOpenGLStereoWidget(class QWidget *,class QFlags<enum Qt::WindowType>)" (__imp_??0QVTKOpenGLStereoWidget@@QEAA@PEAVQWidget@@V?$QFlags@W4WindowType@Qt@@@@@Z) referenced in function "public: void __cdecl Ui_VTKTestClass::setupUi(class QMainWindow *)" (?setupUi@Ui_VTKTestClass@@QEAAXPEAVQMainWindow@@@Z)
1>VTKTest.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QVTKOpenGLStereoWidget::~QVTKOpenGLStereoWidget(void)" (__imp_??1QVTKOpenGLStereoWidget@@UEAA@XZ) referenced in function "public: virtual void * __cdecl QVTKOpenGLStereoWidget::`scalar deleting destructor'(unsigned int)" (??_GQVTKOpenGLStereoWidget@@UEAAPEAXI@Z)
1>VTKTest.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl QVTKOpenGLStereoWidget::metaObject(void)const " (?metaObject@QVTKOpenGLStereoWidget@@UEBAPEBUQMetaObject@@XZ)
1>VTKTest.obj : error LNK2001: unresolved external symbol "protected: virtual void __cdecl QVTKOpenGLStereoWidget::paintEvent(class QPaintEvent *)" (?paintEvent@QVTKOpenGLStereoWidget@@MEAAXPEAVQPaintEvent@@@Z)
1>VTKTest.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl QVTKOpenGLStereoWidget::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QVTKOpenGLStereoWidget@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
1>VTKTest.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl QVTKOpenGLStereoWidget::qt_metacast(char const *)" (?qt_metacast@QVTKOpenGLStereoWidget@@UEAAPEAXPEBD@Z)
1>VTKTest.obj : error LNK2001: unresolved external symbol "protected: virtual void __cdecl QVTKOpenGLStereoWidget::resizeEvent(class QResizeEvent *)" (?resizeEvent@QVTKOpenGLStereoWidget@@MEAAXPEAVQResizeEvent@@@Z)
1>C:\Test\VTKTest\x64\Debug\VTKTest.exe : fatal error LNK1120: 7 unresolved externals
1>Done building project "VTKTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

It seems that both QT Creator and VS2019 cannot find the runtime libraries (in this case QVTKOpenGLStereoWidget). I tried many posts, questions, videos, and tutorials but the issue is not resolving.

Any help will be highly appreciated. Thanks.

Simon
  • 3
  • 2

1 Answers1

0

LIBS should contain not only the path, but also the libraries you want to link. Haven't test my code on Windows/Qt6 yet, but on Linux/Qt5 all necessary VTK libraries are linked automatically when you specify to link libvtkGUISupportQt. So you could try something like this:

LIBS += $$(VTK_DIR)/lib -lvtkGUISupportQt

That worked for me.

Usitha Indeewara
  • 870
  • 3
  • 10
  • 21
Kuba
  • 1