I am a new learner of VTK and I am trying to learn VTK by its examples. I’ve installed VTK and put the “C:\Program Files\VTK\bin” as environment parameter. However when I tried to build one VTK example I failed at Cmake --build stage. The details is as follows:
I chose ClipUnstructuredGridWithPlane as my example and downloaded the files( ClipUnstructuredGridWithPlane.cxx and CMakeLists.txt)
I created build folder and executed cmake -S . -G "MinGW Makefiles" -B build to configure it successfully:
From the screenshot, it seems that the compiler could not find vtk library. But the configuration showes that it already found VTK libs.
BTW the CMakeLists file is as follows(completely copied from the official website):
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(ClipUnstructuredGridWithPlane)
find_package(VTK COMPONENTS
CommonColor
CommonCore
CommonDataModel
CommonTransforms
FiltersGeneral
IOLegacy
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
)
if (NOT VTK_FOUND)
message(FATAL_ERROR "ClipUnstructuredGridWithPlane: Unable to find the VTK build folder.")
endif()
# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(ClipUnstructuredGridWithPlane MACOSX_BUNDLE ClipUnstructuredGridWithPlane.cxx )
target_link_libraries(ClipUnstructuredGridWithPlane PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS ClipUnstructuredGridWithPlane
MODULES ${VTK_LIBRARIES}
)
I am not sure what is the problem.
I am using windows 10, gcc and MinGW. and I’ve put “C:\Program Files\VTK\bin”(which I installed the VTK) as environment parameter path
Thank you for your suggestion! Actually I compiled VTK by setting the compiler to be visual studio 2019. I am now trying to recompile the VTK by MinGW. I’ll update it if I got any news.
From the first path, your Qt5 looks to be MSVC not MinGW. You must be very careful to ensure that MinGW libs are only used, not VC libs and dlls. I jut had a look and for Qt 6.4.1 there is a MinGW 11.2.0 64-bit version.
As an initial step:
I would build VTK without Qt and see if everything builds and works.
but I have already installed Qt5 and when I use CMake-Gui to configure, it recognizes Qt automatically and sets all corresponding variables. So should I leave them alone or just choose No for all Qt options?
For the moment set VTK_GROUP_ENABLE_Qt to No.
Why is QMLPLUGINDUMP_EXECUTABLE pointing to a MSVC version?
I think you need to carefully look at your Paths.
Hi, I just chose “No” for all Qt options(which from my perspective is “build VTK without Qt”) and the Cmake --build command still stopped when it tried to link CXX shared library libvtkCommonCore-9.1d.dll(exactly the same from my previous attempts), the error message is as follows:
c:/progra~2/mingw-~1/winlib~1.0-r/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\CommonCore.dir/objects.a(vtkGenericDataArray.cxx.obj): in function `std::thread::joinable() const':
c:/progra~2/mingw-~1/winlib~1.0-r/mingw64/include/c++/12.2.0/bits/std_thread.h:175: undefined reference to `std::operator==(std::thread::id, std::thread::id)'
c:/progra~2/mingw-~1/winlib~1.0-r/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\CommonCore.dir/objects.a(vtkLogger.cxx.obj): in function `std::equal_to<std::thread::id>::operator()(std::thread::id const&, std::thread::id const&) const':
c:/progra~2/mingw-~1/winlib~1.0-r/mingw64/include/c++/12.2.0/bits/stl_function.h:378: undefined reference to `std::operator==(std::thread::id, std::thread::id)'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [Common\Core\CMakeFiles\CommonCore.dir\build.make:2776: bin/libvtkCommonCore-9.1d.dll] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:3857: Common/Core/CMakeFiles/CommonCore.dir/all] Error 2
mingw32-make: *** [Makefile:135: all] Error 2
I’ve give up using MinGW and chose visual studio, but still there’s one problem: if I use Debug mode, when code runs to renderer->SetBackground(colors->GetColor3d("Wheat").GetData());, an exception is thrown :
but if I chose Release mode then everything is OK.
Thank you. BTW after hours of struggle I finally successfully build MinGW version: I firstly reset all GCC to GCC8(I’ve two GCC, one is v8, the other is v12), then I changed CMAKE_CXX_FLAGS_DEBUG to -O3, and supressed two modules: VtkImagingStatistics and VtkImagingMorphological which showed error message when building process is at 90%. I write down my process in case anyone else needs it.