From 82aa71ce7a53ac714aacf4328f25e12ebb87110b Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 13 Jul 2026 15:44:18 -0700 Subject: [PATCH] Embed debug info in host object libraries to avoid LNK4099 The object libraries embedded into the shipped libnethost.lib and libhostfxr.lib (minipal_objects, hostmisc_c, hostmisc_public) were compiled with /Zi, so their objects reference a build-time vc140.pdb that is not shipped. Consumers linking these static libraries get LNK4099 warnings ("cannot use debug info ... vc140.pdb: no such file"). Compile these object libraries with embedded debug info (/Z7) instead, so the debug info travels inside the objects and no external PDB path is referenced. COMPILE_PDB_NAME/INTERPROCEDURAL_OPTIMIZATION on the final libnethost/libhostfxr targets don't propagate to linked object libraries, so the setting must be applied to each object library. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 45e02cdb-c6a2-4e6a-b749-379d4f1600b5 --- src/native/corehost/CMakeLists.txt | 7 +++++++ src/native/corehost/hostmisc/CMakeLists.txt | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/native/corehost/CMakeLists.txt b/src/native/corehost/CMakeLists.txt index 180994d6ae86ab..93ba4acf9e8947 100644 --- a/src/native/corehost/CMakeLists.txt +++ b/src/native/corehost/CMakeLists.txt @@ -98,6 +98,13 @@ if(NOT CLR_CMAKE_TARGET_BROWSER) # consumption (libnethost, libhostfxr), so LTCG must be disabled to ensure # that non-MSVC toolchains can work with them. set_target_properties(minipal_objects PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) + if (MSVC) + # Embed debug info in the object files (/Z7). CMake does not assign a + # compile PDB to OBJECT libraries, so the objects archived into the shipped + # libnethost/libhostfxr would otherwise reference an absent vc140.pdb, + # producing LNK4099 for consumers. + set_target_properties(minipal_objects PROPERTIES MSVC_DEBUG_INFORMATION_FORMAT Embedded) + endif() add_subdirectory(hostcommon) add_subdirectory(hostmisc) diff --git a/src/native/corehost/hostmisc/CMakeLists.txt b/src/native/corehost/hostmisc/CMakeLists.txt index be2411b560a600..bfde65d28fc61d 100644 --- a/src/native/corehost/hostmisc/CMakeLists.txt +++ b/src/native/corehost/hostmisc/CMakeLists.txt @@ -80,6 +80,12 @@ if(NOT CLR_CMAKE_TARGET_BROWSER) target_link_libraries(hostmisc_public PUBLIC minipal_objects) endif() set_target_properties(hostmisc_public PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) +if (MSVC) + # Embed debug info in the object files (/Z7). CMake does not assign a compile + # PDB to OBJECT libraries, so the objects archived into the shipped libhostfxr + # would otherwise reference an absent vc140.pdb, producing LNK4099 for consumers. + set_target_properties(hostmisc_public PROPERTIES MSVC_DEBUG_INFORMATION_FORMAT Embedded) +endif() add_library(hostmisc::public ALIAS hostmisc_public) @@ -90,3 +96,9 @@ if(NOT CLR_CMAKE_TARGET_BROWSER) target_link_libraries(hostmisc_c PUBLIC minipal_objects) endif() set_target_properties(hostmisc_c PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) +if (MSVC) + # Embed debug info in the object files (/Z7). CMake does not assign a compile + # PDB to OBJECT libraries, so the objects archived into the shipped libnethost + # would otherwise reference an absent vc140.pdb, producing LNK4099 for consumers. + set_target_properties(hostmisc_c PROPERTIES MSVC_DEBUG_INFORMATION_FORMAT Embedded) +endif()