Friday, August 06, 2010

VTK Installation on Windows 64-bit for Visual Studio

VTK Installation on Windows 64-bit for Development in Visual Studio

VTK installation in Windows 32-bit is typically painless, as the platform was already tested by many developers and became mature.  (Yet, if you have a problem with it, the troubleshooting note at the end of this page might help.)  For Windows and VTK 64-bit, however, we may encounter a few issues.  This note describes what I did to install VTK 5.6 on my MS Windows 7 Home Premium 64-bit.  This note should be applicable to those who need to do the same thing.

The first part is for installation with default VTK build options.  These options are VTK_USE_CHARTS, VTK_USE_GEOVIS, VTK_USE_INFOVIS, VTK_USE_N_WAY_ARRAYS, VTK_USE_RENDERING, and VTK_USE_VIEWS.
  1. Download VTK 5.6 source from
  2. Extract it to create a source folder.
  3. Open CMake (I used 2.8.1, and it is supposed to work with the most recent version at
  4. In CMake, choose a source and binary folders (Figure 1).

    Figure 1.  CMake 2.8.1 after source code and binary folder selected.

  5. Click the 'Configure' button.
  6. CMake asks about generator (compiler) we want to use (Figure 2).  The one we want to use is Visual Studio 9 2008 Win64 (the one without suffix Win64 is 32-bit) with 'Use default native compiler'.  We can also use Visual Studio 10 Win64 if a target development platform is Visual Studio 10.  Using MinGW will generate incompatible binary for Visual Studio development.  In addition, 64-bit MinGW is quite tricky to use as of Aug 2010.

    Figure 2. 'Choose compiler' dialog

  7. If initial configuration goes fine, there will be no critical errors and VTK build options will be available for us to choose (Figure 3).

    Figure 3.  Build options for VTK after the initial configuration.  Red regions in CMake highlight new options since the previous configuration.  As this is the first time, every option is new and highlighted.

  8. I used the default options.  This option builds a static libraries, which is what I prefer.
  9. I think options VTK_USE_PARALLEL may help speed up processing in a multi-core system, but I need to learn more about it.  Also, VTK_USE_QT is probably good for me, as I have used Qt a lot recently.  Yet, I need to know what it does first.
  10. Click the 'Configure' button again when options are settled.
  11. Click the 'Generate' button to generate a proper visual studio solution tree.
  12. Go to the output folder specified earlier, you should see 'VTK.sln'.
  13. Open the solution and 'Build Solution'.  It will take a while to finish (around 5-10 minutes).  Note that if you only want to use VTK and do not intend to debug into its source code, it is recommend to build it in the release mode.
  14. In the solution tree, right click on the 'INSTALL' project and 'Build'.  Update Dec 15, 2011: some systems may experience a build error due to write permission to C:\Program Files (x86).  This depends on your Windows settings.  One way to solve this issue is to close Visual Studio and run it 'as administrator' (credit to Alex Southern, see his comment below).
  15. The outputs are kept in C:\Program Files (x86)\VTK.  Both include and lib folders are what we are going to use in further software development.
  16. If you want to build both 32- and 64-bit packages, move the outputs to another folder and repeat the process.  Only the generater in step 6 is needed to change.  We have to move the current outputs because new outputs will be saved to the same folder.

Build VTK with parallel-processing and Qt-support options

Next, I will discuss installation of VTK with additional options for Visual Studio 2008.  These options are VTK_USE_QT and VTK_USE_PARALLEL.  We can jump to step 7 discussed in the last section. At this point, we only need to check the QT and PARALLEL options and then, hit the 'Configure' button the project again.  CMake will configure the project and comes up with two new options highlighted in red (Figure 4).  Once you set QT_QMAKE_EXECUTABLE to your target version, hit the 'Configure' button for the third time.  If every thing goes fine, you will get a refreshed dialog with message "Configuring done", as depicted in Figure 5.  There are chances that you did not succeed or get a wrong Qt version.  If the latter is your problem, read the caption of Figure 4.  If it fails for other reason, please see the troubleshooting note at the end of this document.  I hope it has what you need.

The rest of the process is generally the same.  If you encounter linking errors when you build VTK in Visual Studio, see Topic 2 in the troubleshooting note provided below.

Figure 4.  CMake after the second configuration with QT and PARALLEL.  QT_QMAKE_EXECUTABLE is selected by what you do with Qt integration for Visual Studio.  In other words, CMake checks the path of default Qt version you set in Visual Studio and use it here.  In fact, CMake and VTK build script strictly use the default Qt version.  You cannot effectively change Qt version here, as it will be eventually reset to the VS default version. Therefore, you may need to open VS and change Qt default version to set QT_QMAKE_EXECUTABLE.

Figure 5. A successful configure dialog.

Troubleshooting Note for Qt Option

1. Problem: "I specified qmake path correctly, but it seems that CMake looks for qmake in a wrong path."

You may set QT_QMAKE_EXECUTABLE to point to qmake correctly, but this problem may arise since CMAKE will use outdated qmake properties, such as QT_INSTALL_PREFIX and QT_INSTALL_BINS.  For example, you build Qt in one path and later on you move it to another.  The properties, however, is fixed at the time you build Qt.  You can confirm this issue by going to qmake's make folder and using the command prompt to type 'qmake -query' to see all qmake properties.

If the issue is confirmed, you need to compile qmake again (not the whole Qt library set).  Alternatively, you can just move or copy your Qt directory to the old place to resolve the issue.  If moving or copying Qt folder is not an option, you can quickly re-compile qmake by
  • Rename the bin and qmake folders of Qt to something else.
  • Copy the pristine bin and qmake folders from the Qt source to the Qt folder.
  • Configure Qt from Visual Studio command prompt.  For example, by using 'configure -platform win32-msvc2008 -release -static -opensource -nomake demo -nomake examples -no-qt3support -fast'.  You probably did this before when you compiled Qt libraries.
  • Copy things from the old bin and qmake folders to your current bin and qmake folders, but make sure you do not replace the new qmake you just compiled.
  • Now, you have qmake with updated qmake properties.  I hope you can configure VTK in CMake as usual from this point.

2. Problem: "I got linking errors when I build VTK in Visual Studio.  It complained about PlaySoundW, WSAAsyncSelect, and many more."

Based on my experience, this problem is platform specific.  You may encounter this issue if you use static library version of Qt and the problems in 32-bit and 64-bit platforms are not the same.  These linking problems, however, are related to Windows libraries and occurs when your VTK build script does not correctly include them.

Fortunately, you can include corresponding libraries yourself with ease by following the guidelines described below.
  • Identify problematic projects.  Potential problematic projects are QVTKWidgetPlugin, QVTK, QtChartCxxTests, ChartCxxTests, and QVTKCxxTests.
  • Search the Internet (or use your prior knowledge, or your MSDN documents) to identify corresponding libraries.  For example, the corresponding library of PlaySoundW is Winmm.lib and that of WSAAsyncSelect is Ws2_32.lib.
  • Add the libraries to the Visual Studio project properties, as you do normally.  Basically, you can right click the project in the Solution Explorer of Visual Studio and select 'Properties'.  Then, go to node 'Configuration Properties -> Linker -> Input' and insert the library name to 'Additional Dependencies'.

3. Problem: I checked 'VTK_WRAP_PYTHON' and CMake errors occurred.  It complaint about PYTHON_INCLUDE_DIR AND PYTHON_LIBRARY.

The error message looked like:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.

Please set them or make sure they are set and tested correctly in the CMake files:



The two CMake variables seem to come and go and not consistent over VTK versions.  You might want to add them yourself to CMakeLists.txt.
First, locate IF(VTK_WRAP_PYTHON).  Then, modify the section to something like

  #Addition by Pinyo
  SET(PYTHON_INCLUDE_DIR "C:/Python31/include")
  SET(PYTHON_LIBRARY "C:/Python31/libs/python31.lib")

Please note that PYTHON_LIBRARY is the actual library file, not just a folder (although you sometimes see the term python libraries and think that it is a lot of libraries, not a single file.).
Finally, configure and generate make files as usual.

4. Problem: I used VS 2010 64-bit and CMake 2.8.3 and got Q4VTKWidgetPlugin.h(57): error : Undefined interface.  This corresponds to line Q_INTERFACES(QDesignerCustomWidgetCollectionInterface).

This is, in fact, a CMake problem.  To be exact, the QT_QTDESIGNER_INCLUDE_DIR is not set correctly.  An example of the value is include/QtDesigner/.  This option is available if we want to generate MinGW Makefiles.  This option also was automatically set in the past and it was correct.  For an unknown reason, it does not work on some machines (VTK 5.6.1 as of Feb 18, 2011).

To solve the problem, go to folder GUISupport\Qt and open CMakeLists.txt.  Then, add a line
SET (QT_QTDESIGNER_INCLUDE_DIR "G:/Workspace/Qt/qt-release-4.7.1-vs2010/include/QtDesigner")
Make sure you adjust the ad hoc path to what suits your computer.

The above line should be added right after FIND_PATH(QT_QTDESIGNER_INCLUDE_DIR QDesignerComponents ...), as the function FIND_PATH may not work correctly in your build.

Hope this helps,
Pinyo Taeprasartsit
(Aug 2010, Feb 2011)


texmex9 said...

Very well explained and detailed. Worked flawlessly, and just what I needed. Thanks much.

Anonymous said...

Very well done and, I have basically done the same thing.
The problem I have is, the compiler/linker do not recognize the exported functions. I have fooled around with the directory searches for months now and the system still sqwacks with unrecognized symbols. The problem is, the application I am developing is both a dll and a static lib and I have no problems with my own code.

Divya K. Rathore said...

Thanks for the post!
I have a question.. are there separate versions of Visual Studio 2008 for 32 and 64 Bit Compilation? Or is it just about some flags in the VS settings?

pinyotae said...

Currently, Visual Studio (both 2008 and 2010) is a 32-bit application, but we can use it to build both 32- and 64-bit applications.

In short, if you configure your project correctly, you should be able to build 32- and 64-bit software from the same source code. In VS, you probably see 'Win32' and 'x64' things when you configure your solution. That's the stuff allowing you to specify what kind of bitness you want to work with.

Hope this helps,

Alex Southern said...


Great guide but I have one note for you. Im running Windows 7 and VS2010. At the "right click on INSTALL and Build" step I got 1 failed build and a message saying the VS could not create the folder c:\program files (x86)\vtk\lib\..etc" folder possibly due to admin rights. To fix this, I first cleaned the build and then restarted VS2010 by right clicking on the icon and "Run as administrator".

Perhaps your guide should mention to "Run as administrator" when possible.

Patmo141 said...

I noticed that in the python segment your path points to python31. Have you tested the wrappers with python 3.x? Do they work? I thought python 3.x support wasn't enabled yet.

pinyotae said...

@Patmo141 Thank you for your comment. Frankly, I just noticed that it's v3.1 (I had two versions installed together). As far as I remembered, the program was compiled fine, but I did not check whether or not it worked. Perhaps, it did not since Python 3 is not supported yet. Or, the program was compiled successfully, just because I unknowingly switched back to Python 2.

Patmo141 said...

The build worked perfectly. Thanks so much for your detailed instructions. I ended up not trying to build the python wrappers. My goal is to use ctypes to call some of the functionality in python with Blender.

Benny said...

I've posted 2 new realeases of VTK under Windows x64 and Ubuntu x86.
If this can help someone :

VTK 5.0.8 under Windows x64 or Ubuntu x86 Releases

Anyway, thank's a lot for this tutorial.

aparna john said...

Hi, nice VTK Installation method on Windows 64-bit for Visual Studio.Its really worked well.Thanks...