With the latest C++ Builder release (13.1), building the latest version of VTK (9.6.2) is now  almost straightforward. C++ Builder 13.1 ships with a clang compiler that is of version 20.1.7 (released in early 2025).

Although Embarcadero ships its own version of CMake, the following uses the latest official release of CMake (4.3.4).

The following covers a minimal VTK 9.6.2 build (15 modules) via CMake + Ninja + bcc64x.

Environment

Item Value
VTK source VTK 9.6.2
Compiler bcc64x shipped with C++ Builder 13.1 (clang 20.1.7)
CMake CMake 4.3.4
Generator Ninja 1.10.2

The source code

Use git and check out VTK the repository (see link above). I’m using Tortoise Git and will be checking out the source code into a new branch, based on its tag:

Figure 1: Checking out version 9.6.2 of VTK into folder d:\libs\vtk-9.6.2. Creating a new branch or not is optional.

In order to build VTK with bcc64x the source code will need some minor edits/patches.

Source patches

A fresh VTK 9.6.2 checkout needs four small patches before it builds cleanly with bcc64x. All edits are made so that builds with other compilers, e.g. Microsoft Visual C++ Compiler (MSVC), are unaffected.

In addition to the source changes below, a .def link file is needed at the link stage as the bcc64x compiler have trouble exporting certain templates. The link file is provided below.

Code fix 1: ./Utilities/MetaIO/vtkmetaio/CMakeLists.txt

This fix is straight forward, bcc64x don’t link with Borland library import32.lib, but do link with standard windows libs.

142 endif() 142 endif()
143 143
144 if(WIN32) 144 if(WIN32)
145 if(BORLAND)
145 # bcc64x is clang/MinGW, not classic Borland: it has no import32.lib and links
146 # the standard Windows libs from the else() branch instead.
147 if(BORLAND AND NOT CMAKE_BASE_NAME STREQUAL “bcc64x”)
146 target_link_libraries(${METAIO_TARGET} PRIVATE import32) 148 target_link_libraries(${METAIO_TARGET} PRIVATE import32)
147 else() 149 else()
148 target_link_libraries(${METAIO_TARGET} PRIVATE comctl32 wsock32) 150 target_link_libraries(${METAIO_TARGET} PRIVATE comctl32 wsock32)

Listing 1  Skips linking the classic 32-bit Borland import32 CRT import library for bcc64x, falling through to the normal comctl32/wsock32 link.

Code fix 2: ./CMake/patches/99/FindOpenGL.cmake

Same fix as above.

131 131
132 if (WIN32) 132 if (WIN32)
133 133
134 if(BORLAND)
134 # bcc64x is clang/MinGW (no import32.lib): use the real system opengl32/glu32.
135 if(BORLAND AND NOT CMAKE_BASE_NAME STREQUAL “bcc64x”)
135 set (OPENGL_gl_LIBRARY import32 CACHE STRING “OpenGL library for win32”) 136 set (OPENGL_gl_LIBRARY import32 CACHE STRING “OpenGL library for win32”)
136 set (OPENGL_glu_LIBRARY import32 CACHE STRING “GLU library for win32”) 137 set (OPENGL_glu_LIBRARY import32 CACHE STRING “GLU library for win32”)
137 else() 138 else()

Listing 2  Same import32 problem as above, this time for OpenGL: links the real system opengl32/glu32 instead.

Code fix 3: ./Rendering/OpenGL2/CMakeLists.txt

This fix is related to usage of  Windows DirectX. We don’t need it here. If you do, this build may not work for you.

331 endif () 331 endif ()
332 elseif (VTK_USE_WIN32_OPENGL) 332 elseif (VTK_USE_WIN32_OPENGL)
333 list(APPEND classes 333 list(APPEND classes
334 vtkWin32OpenGLRenderWindow
335 vtkWin32OpenGLDXRenderWindow)
334 vtkWin32OpenGLRenderWindow)
335 # vtkWin32OpenGLDXRenderWindow (OpenGL/Direct3D interop) pulls <wrl/client.h> ->
336 # <roapi.h>, which Embarcadero bcc64x’s MinGW SDK does not ship. Skip it there;
337 # nothing in the core render path instantiates it.
338 if (NOT CMAKE_BASE_NAME STREQUAL “bcc64x”)
339 list(APPEND classes
340 vtkWin32OpenGLDXRenderWindow)
341 endif ()
336 if (NOT VTK_DEFAULT_RENDER_WINDOW_HEADLESS AND NOT has_vtkRenderWindow_override) 342 if (NOT VTK_DEFAULT_RENDER_WINDOW_HEADLESS AND NOT has_vtkRenderWindow_override)
337 vtk_object_factory_declare( 343 vtk_object_factory_declare(
338 BASE vtkRenderWindow 344 BASE vtkRenderWindow

Listing 3  Excludes vtkWin32OpenGLDXRenderWindow.cxx for bcc64x — it pulls in WinRT headers that Embarcadero’s MinGW-flavored SDK does not ship.

Code fix 4: ./Common/Core/CMakeLists.txt

bcc64x have problems exporting some data and function entities. The solution to that problem is an external .def file, wired in via a small guarded addition to Common/Core/CMakeLists.txt

782 vtk_module_compile_features(VTK::CommonCore 782 vtk_module_compile_features(VTK::CommonCore
783 PUBLIC 783 PUBLIC
784 cxx_std_17) 784 cxx_std_17)
785
786 # bcc64x: clang silently drops __declspec(dllexport) on explicit template
787 # instantiation definitions (warning W5736). Members of the extern-template
788 # data-array types (vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate,
789 # vtkScaledSOADataArrayTemplate, vtkImplicitArray, …) are therefore compiled
790 # into the DLL but never placed in its PE export table, so downstream modules
791 # fail to link them. A blanket –export-all-symbols overflows the 64K export
792 # limit (CommonCore has ~210K symbols), so re-export exactly the affected
793 # symbols via a curated .def. See Documents/BUILD_VTK_bcc64x.md for how the list
794 # was generated.
795 if(CMAKE_BASE_NAME STREQUAL “bcc64x”)
796 target_link_options(CommonCore PRIVATE
797 “${CMAKE_CURRENT_SOURCE_DIR}/bcc64x_extra_exports.def“)
798 endif()

Listing 4  The one line fix: guard the extra link options behind CMAKE_BASE_NAME STREQUAL "bcc64x" and point them at a curated bcc64x_extra_exports.def (1,336 symbols, generated once via dumpbin symbol-diffing — not shown inline, but bundled alongside the patches below).

The extra link file: bcc64x_extra_exports.def

The .def file contain about 1300 mangled symbol names. It need to be present in the ./Common/Core folder at link time.

bcc64x_extra_exports.def

The build

Building VTK involves 1) a CMake configure step where needed VTK software modules are selected and myriads of options are available, 2) a generate step where build files suitable for a particular compiler/toolchain are generated, 3) a build step where binaries are compiled into runtime code and 4) an install step, where deployable headers and libraries are installed into a dedicated location for consumption.

There are three folders that are important when using CMake, 1) “Source folder”, 2) “Where to build the binaries” and 3) The “CMake Install Prefix”.

  1. Is where the source code is, in our case, d:\libs\vtk-9.6.2
  2. Is where cmake configuration files and eventually binaries are built
  3. Is where the library (binaries, headers and lib files) is to be installed

In our case, 1 is set, 2 is d:\builds\bcc64x\vtk-9.6.2 and 3) is d:\build\bcc64x

Configuring and building

The bash script below will be used to configure and build VTK using CMake. It uses a toolchain file (see below), that will help configure the CMake build using bcc64x. The main tool chain file brings in two other relevant, one that is a CMake platform file and one dedicated to the VTK build.

So, in a bash shell, create your build directory and copy the toolchain files into it.

Copy the .def file into the ./Common/Core folder as it will be needed at link time.


#!/usr/bin/env bash
# configure_vtk_for_bcc64x — configure and build a minimal VTK 9.6.2 with bcc64x.
# Assumes ninja is on PATH.

set -euo pipefail
vtk_source_dir=""
build_dir=""
repo=""
install_prefix=""

modules=(
  CommonCore CommonDataModel CommonTransforms CommonComputationalGeometry
  FiltersSources FiltersGeneral FiltersModeling RenderingCore RenderingOpenGL2
  RenderingAnnotation RenderingFreeType RenderingVolume RenderingVolumeOpenGL2
  InteractionStyle InteractionWidgets
)

cmake_arguments=(
  -G Ninja
  -S "$vtk_source_dir"
  -B "$build_dir"
  -DCMAKE_TOOLCHAIN_FILE="$repo/CMake/bcc64x-toolchain.cmake"
  -DROOTDIR="C:/Program Files (x86)/Embarcadero/Studio/37.0"
  -DCMAKE_BUILD_TYPE=Release
  -DCMAKE_INSTALL_PREFIX="$install_prefix"
  -DBUILD_SHARED_LIBS=ON
  -DVTK_REQUIRE_LARGE_FILE_SUPPORT_EXITCODE=0
  -DVTK_BUILD_ALL_MODULES=OFF
  -DVTK_GROUP_ENABLE_StandAlone=DONT_WANT
  -DVTK_GROUP_ENABLE_Rendering=DONT_WANT
  -DVTK_GROUP_ENABLE_Views=DONT_WANT
  -DVTK_GROUP_ENABLE_Imaging=DONT_WANT
  -DVTK_MODULE_ENABLE_VTK_hdf5=NO
  -DVTK_MODULE_ENABLE_VTK_netcdf=NO
  -DCMAKE_RC_COMPILER="C:/Program Files (x86)/Windows Kits/10/bin/10.0.22621.0/x64/rc.exe"
  -DCMAKE_CXX_FLAGS="-Wno-ignored-attributes -D_POSIX_THREAD_SAFE_FUNCTIONS"
  -DCMAKE_C_FLAGS="-Wno-ignored-attributes -D_POSIX_THREAD_SAFE_FUNCTIONS -fcommon"
)

for m in "${modules[@]}"; do
  cmake_arguments+=("-DVTK_MODULE_ENABLE_VTK_${m}=YES")
done

cmake "${cmake_arguments[@]}"

Listing 5 The complete Bash configure-and-build script. It selects 15 modules, builds up the cmake_arguments array pointing CMake at the bcc64x toolchain file, disables the module groups and third-party libraries that don’t build under bcc64x (hdf5, netcdf), supplies the RC compiler path (using the one from Visual Studio install) and the portability compile flags, then runs cmake.


/d/builds/bcc64x/vtk-9.6.2 $ 
/d/builds/bcc64x/vtk-9.6.2 $ 
/d/builds/bcc64x/vtk-9.6.2 $ 
/d/builds/bcc64x/vtk-9.6.2 $ vtk_source_dir=D:/libs/vtk-9.6.2 install_prefix=D:/build/bcc64x ./configure_vtk_for_bcc64x.sh

Listing 6 How to run the configure script in a bash shell.

After the configure phase of CMake, it will take a while, VTK can be built and installed, simply by entering “ninja install” from where the configure script was executed.

Appendix: Toolchain files

The CMake toolchain files are listed below.

bcc64x-toolchain.cmake

The entry-point toolchain file — the one you pass as -DCMAKE_TOOLCHAIN_FILE. Sets the target to Windows/AMD64, points the compiler at bcc64x.exe, pre-includes the platform shim so that CMake’s built-in Borland module never runs, wires in the rules-override and locates ninja. bcc64x-toolchain.cmake

Windows-Embarcadero.cmake

Platform shim. Purpose: supply the C/C++ -std= dialect mappings and granular compile-feature lists that CMake’s Embarcadero compiler id lacks, sets the MinGW/lld library naming (empty prefix, .dll/.lib/.a suffixes, llvm-ar), and defines the clang link rules (-shared, explicit -lc++, --out-implib). Windows-Embarcadero.cmake

bcc64x-rules-override.cmake

Post platform link rule corrections, included via CMAKE_USER_MAKE_RULES_OVERRIDE so it runs after Platform/Windows.cmake. bcc64x-rules-override.cmake

bcc64x-vtk-toolchain.cmake

VTK-specific wrapper. bcc64x-vtk-toolchain.cmake

Download all of the above mentioned files, including a git patch file to make the VTK source code changes above in one go.
vtk-bcc64x-build-files.zip

Leave a Reply