Compile error when ling static release config of VRK 9.3.0 via vcpkg

Hi ,
I try to build c++ project with vtk .
OS: windows 10
Package manager : vcpkg
Build system: cmake
The compiler: MSVC 2022
VTK: version 9.3.0
I can’t build project in release configuration.
The error is follow : LNK2038 mismatch detected for ‘_ITERATOR_DEBUG_LEVEL’: value ‘2’ doesn’t match value ‘0’
Command to install VTK via vcpkg:
vcpkg install vtk --triplet x64-windows-static --clean-after-build

Static debug project config build without errors.

Dynamic linkage config (release and debug) build without errors.

Is there something important to install VTK with static linkage via vcpkg ?

Something is still being built in debug mode. You cannot (easily) mix debug and release software on Windows.

Thanks.

I install both debug and release verisions of VTK via vcpkg .

release dynamic - compilation success
debug dynamic - compilation success
debug static- compilation success
release static- compilation error:
LNK2038 mismatch detected for ‘_ITERATOR_DEBUG_LEVEL’: value ‘2’

I use the same approach to install other libraries as well, for example, with Boost all configs works correctly.

Hmm. We have a Windows static build which uses Release in CI. Can you get more information about the link line that makes the error?

Minimal code example :
main.cpp:

#include <vtkCellArray.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkPoints.h>
#include <vtkSmartPointer.h>
#include <vtkUnstructuredGrid.h>

#include <vtkXMLMultiBlockDataWriter.h>
#include <iostream>

int main() {
  std ::cout << "Well done \n";

  //  MultiBlockDataSet
  vtkNew<vtkMultiBlockDataSet> mbDataSet;

  // Add some dataset
  vtkNew<vtkUnstructuredGrid> grid1;
  vtkNew<vtkPoints> points1;
  points1->InsertNextPoint(0, 0, 0);
  points1->InsertNextPoint(1, 0, 0);
  points1->InsertNextPoint(0.5, 1, 0);

  vtkNew<vtkCellArray> cells1;
  cells1->InsertNextCell({0, 1, 2});

  grid1->SetPoints(points1);
  grid1->SetCells(VTK_TRIANGLE, cells1);
  mbDataSet->SetBlock(0, grid1);
  // Create writer and write
  vtkNew<vtkXMLMultiBlockDataWriter> writer;
  writer->SetInputData(mbDataSet);
  writer->SetFileName("Groups.vtm");
  writer->Write();
  return 0;
}

CMakeLists.txt :

cmake_minimum_required (VERSION 3.20)
project (VTK_test LANGUAGES CXX)
set(VCPKG_TARGET_TRIPLET x64-windows-static)
include( $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
include_directories( ${INCLUDE_DIRECTORIES}  $ENV{VCPKG_ROOT}/installed/x64-windows-static/include/ )

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(VTK_test_target   main.cpp )


set_target_properties (VTK_test_target PROPERTIES CXX_STANDARD 20 CMAKE_CXX_STANDARD_REQUIRED ON)
# Static link option
set_property (TARGET VTK_test_target PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")


target_link_libraries(VTK_test_target PUBLIC ${VTK_LIBRARIES})

command to instal vtk via vcpkg :

vcpkg install vtk   --triplet x64-windows-static --clean-after-build

The compiler output

10 mismatches detected
mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in main.obj
mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in main.obj
mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in main.obj
mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in main.obj
mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in main.obj
mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj

The problem might be related to CMake Policy 0091. This policy changes the MSVC_RUNTIME_LIBRARY behavior.

Try this at the top of your CMakeLists.txt:

cmake_minimum_required (VERSION 3.20)
if (POLICY CMP0091)
  cmake_policy(SET CMP0091 NEW)
endif ()