From b9f8e3b72ef20732317d30274b5ed0ebbf561cb7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 23 Jan 2026 01:55:47 +0100 Subject: [PATCH] Fix MT use with libxml2 < 2.9.10 under Linux libxml2 headers used to require _REENTRANT to be defined to actually enable support for multiple threads and even though this was changed back in cf68fe3d (Always define LIBXML_THREAD_ENABLED when enabled, 2019-02-27), still add -pthread to ensure _REENTRANT is defined just in case we use an older version. --- src/CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 059ac99..e378a2b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -74,6 +74,20 @@ target_include_directories(xmlwrapp $ $ ) + +# Always use -pthread under Linux: this is required to ensure that _REENTRANT +# is defined as libxml2 < 2.9.10 needs it to enable thread-safe operation. +# +# Note that using find_package(Threads) wouldn't work as it doesn't add any +# compilation flags on modern Linux systems deeming them unnecessary (which +# is formally correct but breaks using libxml2 in practice). +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_compile_options(xmlwrapp + PRIVATE + -pthread + ) +endif() + target_link_options(xmlwrapp PUBLIC ${LIBXML2_LDFLAGS}