[llvm] [cmake] Use the C++ linker when checking libxml2 (PR #221970)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 04:59:41 PDT 2026


https://github.com/miyanyan created https://github.com/llvm/llvm-project/pull/221970

When libxml2 is built statically with ICU support, its link interface contains C++ libraries. `check_symbol_exists()` uses the C linker driver, causing the libxml2 check to fail on unresolved C++ runtime symbols and incorrectly report that `xmlReadMemory` is unavailable.

This issue was found in https://github.com/microsoft/vcpkg/pull/53727

>From a19865fac5c52d8379c547a5aaa3ebc3a3022bd6 Mon Sep 17 00:00:00 2001
From: miyanyan <1138989048 at qq.com>
Date: Tue, 8 Sep 2026 19:38:52 +0800
Subject: [PATCH] [cmake] Use the C++ linker when checking libxml2

---
 llvm/cmake/config-ix.cmake | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index ab02554af0b53..b1ac354f399e3 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -228,7 +228,7 @@ if(LLVM_ENABLE_LIBXML2)
     # library on a 64-bit system which would result in a link-time failure.
     cmake_push_check_state()
     list(APPEND CMAKE_REQUIRED_LIBRARIES LibXml2::LibXml2)
-    check_symbol_exists(xmlReadMemory libxml/xmlreader.h HAVE_LIBXML2)
+    check_cxx_symbol_exists(xmlReadMemory libxml/xmlreader.h HAVE_LIBXML2)
     cmake_pop_check_state()
     if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON AND NOT HAVE_LIBXML2)
       message(FATAL_ERROR "Failed to configure libxml2")
@@ -242,7 +242,7 @@ if(LLVM_ENABLE_LIBXML2)
       list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBXML2_INCLUDE_DIR})
       list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBXML2_STATIC_LIBRARY} ${LIBXML2_STATIC_DEPS})
       list(APPEND CMAKE_REQUIRED_DEFINITIONS ${LIBXML2_DEFINITIONS})
-      check_symbol_exists(xmlReadMemory libxml/xmlreader.h HAVE_LIBXML2_STATIC)
+      check_cxx_symbol_exists(xmlReadMemory libxml/xmlreader.h HAVE_LIBXML2_STATIC)
       cmake_pop_check_state()
       if(NOT HAVE_LIBXML2_STATIC)
         message(FATAL_ERROR "Failed to configure static libxml2, but LLVM_USE_STATIC_LIBXML2=ON")



More information about the llvm-commits mailing list