# How to build VTK-9.1.0 Static Library?

**URL:** https://discourse.vtk.org/t/how-to-build-vtk-9-1-0-static-library/8339
**Category:** Support
**Created:** [April 20, 2022, 3:06pm UTC](https://discourse.vtk.org/t/how-to-build-vtk-9-1-0-static-library/8339 "2022-04-20T15:06:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Geeta](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/a88e57/32.png) [@Geeta](https://discourse.vtk.org/u/Geeta)
#### Post date: [April 20, 2022, 3:06pm UTC](https://discourse.vtk.org/t/how-to-build-vtk-9-1-0-static-library/8339/1 "2022-04-20T15:06:00Z")

</div>

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 . 🙂

 ![image](https://discourse.vtk.org/uploads/default/original/2X/e/e9f56c87f9dbf3da363d13e1d32621a01767b095.png)

 ![image](https://discourse.vtk.org/uploads/default/original/2X/a/a701b30b16b22ef0b97c28d79dfbfed03b779ea9.png)

---

<div class="post-metadata">

### Author: ![Geeta](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/a88e57/32.png) [@Geeta](https://discourse.vtk.org/u/Geeta)
#### Post date: [April 20, 2022, 3:17pm UTC](https://discourse.vtk.org/t/how-to-build-vtk-9-1-0-static-library/8339/2 "2022-04-20T15:17:38Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [May 15, 2022, 4:52pm UTC](https://discourse.vtk.org/t/how-to-build-vtk-9-1-0-static-library/8339/3 "2022-05-15T16:52:51Z")

</div>

> [@Geeta](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![Dean](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@Dean](https://discourse.vtk.org/u/Dean)
#### Post date: [September 16, 2022, 7:59pm UTC](https://discourse.vtk.org/t/how-to-build-vtk-9-1-0-static-library/8339/4 "2022-09-16T19:59:04Z")

</div>

> [@ben.boeckel](#):
>
> 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.

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 .

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 16, 2022, 10:11pm UTC](https://discourse.vtk.org/t/how-to-build-vtk-9-1-0-static-library/8339/5 "2022-09-16T22:11:09Z")

</div>

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

There is information about MD vs MT here: [msvc-static-runtime-option-mt-is-overwritten-by-md/3651](https://discourse.vtk.org/t/msvc-static-runtime-option-mt-is-overwritten-by-md/3651)

---

<div class="post-metadata">

### Author: ![Dean](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@Dean](https://discourse.vtk.org/u/Dean)
#### Post date: [September 17, 2022, 5:34pm UTC](https://discourse.vtk.org/t/how-to-build-vtk-9-1-0-static-library/8339/6 "2022-09-17T17:34:59Z")

</div>

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](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
