How to build VTK-9.1.0 Static Library?

I have built VTK-9.1.0 Static library by keeping BUILD_SHARED_LIBS = OFF.
But when I use this library in my module[vtkDlgApp] I get Linking errors.

Severity Code Description Project File Line Suppression State
Error LNK2038 mismatch detected for ‘RuntimeLibrary’: value ‘MDd_DynamicDebug’ doesn’t match value ‘MTd_StaticDebug’ in StdAfx.obj vtkDlgApp D:\DataDesignProjects\VTK_Examples\Build\vtkDLG\vtkRenderingOpenGL2-9.1d.lib(vtkRenderingOpenGL2ObjectFactory.obj) 1

vtkDlgApp: Project settings
Use of MFC = Use Standard Windows Libraries
Runtime Library = Multi-threaded Debug (/MTd)

If I change the porject settings to dynamic then vtkDlgApp exe is built.
Use of MFC =Use MFC in a Shared DLL
Runtime Library = Multi-threaded Debug DLL (/MDd)

I think, there is problem in VTK-9.1.0 Static library .
So can anybody help building the VTK-9.1.0 Static library and using it in a MFC dialog module?

Thanks in advance . :slight_smile:

cmake_dependent_option(VTK_ENABLE_KITS “Enable kits compilation” OFF

Static builds don’t make sense with kits. Ignore the flag if shared

libraries aren’t being built.

“VTK_BUILD_SHARED_LIBS” OFF)
mark_as_advanced(VTK_ENABLE_KITS)

what does this mean ?

It means that a static kit build makes no sense. So if you’re making a static build, the user’s kit request is just ignored and treated as if it is off.

As for the main question…it seems you’re trying to request a Debug build from CMake, but then try to use a release version of MFC. This is not supported. If this isn’t correct, more specific information will be needed.

I am also looking to statically link Qt to VTK at runtime. Can someone explain why a static build of VTK makes no sense in this case ? I built Qt 5.15.2 debug libs statically, configuring with -static and -static-runtime and ensuring /MTd was set in mkspecs for win32-msvc . I run CMake on my vtk 9.1 source, turned off SHARED_LIBS, build Debug. When I open the VS sln in VS 2020, the flags are all set to /MD and not /MTd .

The “makes no sense” was with regards to “VTK_ENABLE_KITS=ON”, so it doesn’t apply to your situation :slight_smile:

There is information about MD vs MT here: msvc-static-runtime-option-mt-is-overwritten-by-md/3651

thank you David. For anyone building Qt 5.15.2 static from source with VTK 9.1.0 on Win 10 using
Visual Studio 2020

open x64 native tools command prompt for VS 2022

mkdir C:\Qt
cd C:\Qt
mkdir qt5-static
git clone https://code.qt.io/qt/qt5.git qt5
cd qt5
git switch 5.15.2
set QTDIR=C:\Qt\qt5\qtbase
set PATH=C:\Qt\qt5\qtbase\bin;%PATH%
perl init-repository

edit C:\Qt\qt5\qtbase\mkspecs\win32-msvc\qmake.conf:
QMAKE_CFLAGS_RELEASE = -O2 -MT -MP2
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi -MP2
QMAKE_CFLAGS_DEBUG = -Zi -MTd -MP2

configure -prefix “C:\Qt\qt5-static” -debug-and-release -static -opensource -confirm-license -mp -sql-sqlite -opengl desktop -no-openssl
-skip webengine
-skip lottie
-skip svg
-skip activeqt
-skip gamepad
-skip location
-skip sensors
-skip speech
-skip quick3d
-skip quickcontrols
-skip quickcontrols2
-skip quicktimeline
-skip webchannel
-skip wayland
-no-freetype
-no-gif
-no-libpng
-no-libjpeg
-no-tiff
-nomake tests -nomake examples -static-runtime -platform win32-msvc -v
nmake
nmake install

cd c:
mkdir c:\code
cd c:\code
mkdir C:\code\repository
mkdir C:\code\build
cd C:\code\repository
git clone https://github.com/Kitware/VTK.git

run cmakegui
point to vtk source folder
point to vtk build folder
click Configure
uncheck build_shared_libs
cmake_configuration_types Debug
qt5_dir C:/Qt/qt5-static/lib/cmake/Qt5
check Advanced
vtk_group_enable_qt=WANT
VTK_MODULE_ENABLE_VTK_GUISupportQtQuick:STRING=DONT_WANT
add STRING var in CMakeGUI:
CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug

open solution in VS → Build → ALL_BUILD

after completion, in shell
cd c:\code\build\vtk_9.1.0
cmake -P cmake_install.cmake