Skip to content

Build Instructions VTK

Bernhard Froehler edited this page Jan 22, 2025 · 24 revisions

Up to Windows Build / Linux Build.

See also the official VTK build instructions.

Getting the Source Code

  • Download the latest release source archive (.tar.gz) from VTK Downloads.
  • Extract archive to an arbitrary folder; the folder containing the CMakeLists.txt is referenced on this page as vtk-src-dir, this could e.g. be C:\Tools\vtk\VTK-9.1.0 on Windows or /home/developer/devel/vtk/src-9.1.0 on Linux. Note: On Windows, make sure that the full path you choose for vtk-src-dir (and vtk-bin-dir, see below) is not too long (recommendation: below 25 characters in total), otherwise you might see errors regarding the command line for moc being too long.

Configuration

  • Start CMake.
  • Make sure the "Advanced" checkbox is ticked.
  • Specify vtk-src-dir under "Where is the source code", and an arbitrary vtk-bin-dir (e.g. C:\Tools\vtk\bin-9.1.0) under "Where to build the binaries".
  • Press "Configure".
  • Press "Yes" when asked whether the build directory should be created.
  • When asked, specify the desired generator; e.g. "Visual Studio 16 2019" / "Visual Studio 17 2022" on Windows, or "Ninja" / "Unix Makefiles" on Linux; these generators are the ones that we use internally; choosing another generator should be no problem, but as we haven't tested them, you might encounter problems, if so please let us know!
  • Typically, you'll want to leave "Use default native compilers" checked; choose "Specify native compilers" if you know what you're doing and you want to use a different compiler (which you will be required to select in a next step).
  • Depending on which version of VTK you are using, the options to set vary:

Configuration options

If you don't see one of the settings described here, you probably forgot to check the "Advanced" checkmark as described above.

  • Enable BUILD_SHARED_LIBS (should be enabled by default)
  • Set VTK_MODULE_ENABLE_VTK_GUISupportQt to YES
  • Set VTK_MODULE_ENABLE_VTK_RenderingQt to YES
  • Set VTK_MODULE_ENABLE_VTK_ViewsQt to YES
  • Set VTK_MODULE_ENABLE_VTK_RenderingContextOpenGL2 to YES
  • Optional: Set VTK_MODULE_ENABLE_VTK_RenderingOpenVR, VTK_MODULE_ENABLE_VTK_RenderingOpenXR or both to YES if you plan to build the ImNDT/VRAnnotations/XVRA module. Note that we so far only tested VR features under Windows. Make sure to check the OpenVR and/or OpenXR section there for notes on which version of VTK is working well with VR and with which backend.
  • Press "Configure" again.
  • You will probably receive an error message that CMake Could not find a valid Qt installation. In that case, set either the Qt5_DIR or Qt6_DIR variable to the version/buildtype/lib/cmake/Qt5/6 sub-directory of the Qt installation folder (with Qt 6.3.2 and the Visual Studio 2019 64 bit build installed, you would need to set Qt6_DIR to Qt-installation-dir/6.3.2/msvc2019_64/lib/cmake)
  • Press "Configure" again.
  • If you have enabled OpenVR by setting VTK_MODULE_ENABLE_VTK_RenderingOpenVR to YES, you will receive an error regarding CMake not finding the OpenVR SDK. To fix this:
    • Download the archive of the latest OpenVR SDK.
    • Extract the archive.
    • In the CMake window where you configure VTK:
      • Set OpenVR_INCLUDE_DIR to the headers subfolder of where you extracted the OpenVR archive.
      • Set OpenVR_LIBRARY to the respective file required for linking to the SDK; on Windows, this is the file lib/win64/openvr_api.lib inside the SDK, on Linux, this is the file bin/linux64/libopenvr_api.so (inside of where you extracted the OpenVR archive).
  • If you have enabled OpenXR by setting VTK_MODULE_ENABLE_VTK_RenderingOpenXR to YES, you will receive an error regarding CMake not finding the OpenXR SDK. To fix this:
    • Download the archive for the latest OpenXR SDK Source. Note that the Khronos Group currently only provides pre-built binaries for Windows; see the OpenXR section in the Windows build instructions for more details on the specific file to download.
    • Extract the archive.
    • In the CMake window where you configure VTK:
      • Set OpenXR_INCLUDE_DIR to the include/openxr subfolder of where you extracted the OpenXR archive.
      • Set OpenXR_LIBRARY to the loader library; on Windows, this is the file x64/lib/openxr_loader.lib inside the SDK.

Finishing configuration

  • When using a "single-configuration" generator, such as "Ninja" or "Unix Makefiles", also set CMAKE_BUILD_TYPE to the build type you want to create (e.g., Debug if you plan to fix problems in open_iA, Release if you plan to use it productively and run long-running operations). For Visual Studio generators, you don't need to create/modify this setting (it is a multi-configuration generator, the option typically even will not exist).
  • Press "Configure" one last time; if there still are errors, the corresponding messages should give you a hint as to what to do to resolve them.
  • When there are no more errors, and "Configuring done" is shown at the bottom of the log, press "Generate".

Building

  • On Windows with Visual Studio:
    • Click "Open Project" (check carefully that it opens with the correct Visual Studio version in case you have multiple versions installed!), or open vtk.sln in vtk-bin-dir in Visual Studio
    • Build desired configuration(s) (for example Debug), e.g. via "Build"->"Build Solution", or multiple configurations at once via "Build"->"Batch Build".
  • On Unix/Linux:
    • Open a command line in vtk-bin-dir.
    • Depending on the chosen generator:
      • If "Unix Makefiles", run make -j 8 - the 8 specifies the number of parallel compilations, you can adapt that to better match the number of (virtual) processor cores in your computer
      • If "Ninja, run ninja

If there are any problems, check the respective troubleshooting section:

Navigation:

Clone this wiki locally