[libcxx-commits] [libcxx] [libcxx] Remove dependency on msvcrt/libcmt (PR #209663)

Petr Hosek via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 20 00:04:09 PDT 2026


https://github.com/petrhosek updated https://github.com/llvm/llvm-project/pull/209663

>From bdc1e5a119d524afb455077280725d0a84d28521 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Sat, 11 Jul 2026 22:21:41 +0000
Subject: [PATCH] [libcxx] Remove dependency on msvcrt/libcmt

This is no longer needed in MSVC mode now after #94977 and #150182.
---
 libcxx/CMakeLists.txt                           | 17 -----------------
 .../configs/llvm-libc++-shared-clangcl.cfg.in   |  5 +----
 ...vm-libc++-shared-no-vcruntime-clangcl.cfg.in |  5 +----
 .../configs/llvm-libc++-static-clangcl.cfg.in   |  5 +----
 4 files changed, 3 insertions(+), 29 deletions(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 8e63054dd11ec..e28bbfaa0605d 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -741,23 +741,6 @@ function(cxx_link_system_libraries target)
   endif()
 
   if (MSVC)
-    if ((NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
-        OR (CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug"))
-      set(LIB_SUFFIX "d")
-    else()
-      set(LIB_SUFFIX "")
-    endif()
-
-    if (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")
-      set(CRT_LIB "msvcrt")
-      set(CXX_LIB "msvcprt")
-    else()
-      set(CRT_LIB "libcmt")
-      set(CXX_LIB "libcpmt")
-    endif()
-
-    target_link_libraries(${target} PRIVATE ${CRT_LIB}${LIB_SUFFIX}) # C runtime startup files
-    target_link_libraries(${target} PRIVATE ${CXX_LIB}${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals.
     # Required for standards-complaint wide character formatting functions
     # (e.g. `printfw`/`scanfw`)
     target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers)
diff --git a/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
index 5196ca32479ac..8aacd6d8d6af0 100644
--- a/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
@@ -5,22 +5,19 @@ dbg_include = ''
 runtime_library = '@CMAKE_MSVC_RUNTIME_LIBRARY@'
 if runtime_library == '' or runtime_library.endswith('DLL'):
     fms_runtime_lib = 'dll'
-    cxx_lib = 'msvcprt'
 else:
     fms_runtime_lib = 'static'
-    cxx_lib = 'libcpmt'
 
 if '@CMAKE_BUILD_TYPE@'.upper() == 'DEBUG':
     dbg_include = ' -D_DEBUG -include set_windows_crt_report_mode.h'
     fms_runtime_lib += '_dbg'
-    cxx_lib += 'd'
 
 config.substitutions.append(('%{flags}', '--driver-mode=g++'))
 config.substitutions.append(('%{compile_flags}',
     '-fms-runtime-lib=' + fms_runtime_lib + ' -nostdinc++ -I %{target-include-dir} -I %{include-dir} -I %{libcxx-dir}/test/support -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX' + dbg_include
 ))
 config.substitutions.append(('%{link_flags}',
-    '-nostdlib -L %{lib-dir} -lc++ -l' + cxx_lib
+    '-nostdlib -L %{lib-dir} -lc++'
 ))
 config.substitutions.append(('%{exec}',
     '%{executor} --execdir %{temp} --prepend_env PATH=%{install-prefix}/bin -- '
diff --git a/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in
index ce142b1a9d644..378f44986f104 100644
--- a/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in
@@ -6,22 +6,19 @@ dbg_include = ''
 runtime_library = '@CMAKE_MSVC_RUNTIME_LIBRARY@'
 if runtime_library == '' or runtime_library.endswith('DLL'):
     fms_runtime_lib = 'dll'
-    cxx_lib = 'msvcprt'
 else:
     fms_runtime_lib = 'static'
-    cxx_lib = 'libcpmt'
 
 if '@CMAKE_BUILD_TYPE@'.upper() == 'DEBUG':
     dbg_include = ' -D_DEBUG -include set_windows_crt_report_mode.h'
     fms_runtime_lib += '_dbg'
-    cxx_lib += 'd'
 
 config.substitutions.append(('%{flags}', '--driver-mode=g++'))
 config.substitutions.append(('%{compile_flags}',
     '-fms-runtime-lib=' + fms_runtime_lib + ' -nostdinc++ -I %{include-dir} -I %{target-include-dir} -I %{libcxx-dir}/test/support -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX -D_HAS_EXCEPTIONS=0' + dbg_include
 ))
 config.substitutions.append(('%{link_flags}',
-    '-nostdlib -L %{lib-dir} -lc++ -l' + cxx_lib
+    '-nostdlib -L %{lib-dir} -lc++'
 ))
 config.substitutions.append(('%{exec}',
     '%{executor} --execdir %{temp} --prepend_env PATH=%{install-prefix}/bin -- '
diff --git a/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in
index 4be1e1afa1c5b..f05c78e1068c6 100644
--- a/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in
@@ -5,22 +5,19 @@ dbg_include = ''
 runtime_library = '@CMAKE_MSVC_RUNTIME_LIBRARY@'
 if runtime_library == '' or runtime_library.endswith('DLL'):
     fms_runtime_lib = 'dll'
-    cxx_lib = 'msvcprt'
 else:
     fms_runtime_lib = 'static'
-    cxx_lib = 'libcpmt'
 
 if '@CMAKE_BUILD_TYPE@'.upper() == 'DEBUG':
     dbg_include = ' -D_DEBUG -include set_windows_crt_report_mode.h'
     fms_runtime_lib += '_dbg'
-    cxx_lib += 'd'
 
 config.substitutions.append(('%{flags}', '--driver-mode=g++'))
 config.substitutions.append(('%{compile_flags}',
     '-fms-runtime-lib=' + fms_runtime_lib + ' -nostdinc++ -I %{target-include-dir} -I %{include-dir} -I %{libcxx-dir}/test/support -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX' + dbg_include
 ))
 config.substitutions.append(('%{link_flags}',
-    '-nostdlib -L %{lib-dir} -llibc++ -l' + cxx_lib
+    '-nostdlib -L %{lib-dir} -llibc++'
 ))
 config.substitutions.append(('%{exec}',
     '%{executor} --execdir %{temp} -- '



More information about the libcxx-commits mailing list