A standalone Debug build with clang-cl never finishes compiling. CMake sets MSVC for clang-cl
as well as for cl, so libmdbx adds /WX and applies MSVC-only flags that clang-cl merely warns
about — and /WX turns each warning into an error.
Environment
|
|
| libmdbx |
v0.14.3 (f7a3a932) |
| compiler |
clang-cl 22.1.3, target x86_64-pc-windows-msvc |
| CMake |
4.3.1-msvc1, Ninja generator |
| OS |
Windows 11 26200, x86_64 |
Reproduce
cmake -S libmdbx -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DMDBX_BUILD_TOOLS=ON
cmake --build build
The three diagnostics
1. /experimental:c11atomics, every C and C++ TU — this one alone stops the build:
clang-cl: error: argument unused during compilation: '/experimental:c11atomics'
[-Werror,-Wunused-command-line-argument]
Chain: cmake/compiler.cmake:436 runs
check_c_compiler_flag("/experimental:c11atomics" MSVC_C11_MAD_ATOMICS). clang-cl does not implement
the flag but only warns, so the probe passes and the cache records
MSVC_C11_MAD_ATOMICS:INTERNAL=1. cmake/compiler.cmake:913 then adds /WX, and
CMakeLists.txt:775 applies the flag on the strength of the cached probe.
2. mdbx.h++:1499 — present in both static and shared builds:
mdbx.h++(1499,7): error: attribute 'unlikely' has no effect when annotating
an 'if constexpr' statement [-Werror,-Wignored-attributes]
MDBX_CXX20_UNLIKELY is applied to the branch of an if MDBX_IF_CONSTEXPR (...) in
propagate().
3. dllexport on explicit instantiations — with MDBX_BUILD_SHARED_LIBRARY=ON (the default):
mdbx.h++(5067,1): error: explicit instantiation declaration should not be 'dllexport'
[-Werror,-Wdllexport-explicit-instantiation-decl]
mdbx.h++(5070,1): error: same
mdbx.c++(2197,1): error: explicit instantiation definition is not exported without 'dllexport'
[-Werror,-Wignored-attributes]
mdbx.c++(2200,1): error: same
These disappear under -DMDBX_BUILD_SHARED_LIBRARY=OFF; (1) and (2) remain.
Why Release and subdirectory consumers do not see it
/WX is added only for Debug, or under CI, or with a multi-config generator
(cmake/compiler.cmake:907-913), so Release merely warns.
The /WX block also lives inside macro(setup_compile_flags) (cmake/compiler.cmake:752), so a
project that adds libmdbx via add_subdirectory() without calling that macro is unaffected. The
flags are still applied to the targets in that case — we see /experimental:c11atomics on every
libmdbx compile line — so the warnings are emitted on every build; they simply are not fatal.
Suggested fix
For (1), either probe under the conditions the flag is later used in:
if(MSVC)
set(CMAKE_REQUIRED_FLAGS "/WX")
check_c_compiler_flag("/experimental:c11atomics" MSVC_C11_MAD_ATOMICS)
unset(CMAKE_REQUIRED_FLAGS)
endif()
or skip the flag for clang-cl, which does not implement it:
if(MSVC AND NOT CMAKE_COMPILER_IS_CLANG)
check_c_compiler_flag("/experimental:c11atomics" MSVC_C11_MAD_ATOMICS)
endif()
The second matches the existing guard at cmake/compiler.cmake:524.
(2) and (3) are source-level and independent of the flag handling.
Workaround
Build a non-Debug configuration. -DMSVC_C11_MAD_ATOMICS=0 clears (1) on its own but leaves (2)
and (3), so it is not sufficient by itself.
A standalone
Debugbuild withclang-clnever finishes compiling. CMake setsMSVCfor clang-clas well as for cl, so libmdbx adds
/WXand applies MSVC-only flags that clang-cl merely warnsabout — and
/WXturns each warning into an error.Environment
f7a3a932)x86_64-pc-windows-msvcReproduce
The three diagnostics
1.
/experimental:c11atomics, every C and C++ TU — this one alone stops the build:Chain:
cmake/compiler.cmake:436runscheck_c_compiler_flag("/experimental:c11atomics" MSVC_C11_MAD_ATOMICS). clang-cl does not implementthe flag but only warns, so the probe passes and the cache records
MSVC_C11_MAD_ATOMICS:INTERNAL=1.cmake/compiler.cmake:913then adds/WX, andCMakeLists.txt:775applies the flag on the strength of the cached probe.2.
mdbx.h++:1499— present in both static and shared builds:MDBX_CXX20_UNLIKELYis applied to the branch of anif MDBX_IF_CONSTEXPR (...)inpropagate().3.
dllexporton explicit instantiations — withMDBX_BUILD_SHARED_LIBRARY=ON(the default):These disappear under
-DMDBX_BUILD_SHARED_LIBRARY=OFF; (1) and (2) remain.Why
Releaseand subdirectory consumers do not see it/WXis added only forDebug, or underCI, or with a multi-config generator(
cmake/compiler.cmake:907-913), soReleasemerely warns.The
/WXblock also lives insidemacro(setup_compile_flags)(cmake/compiler.cmake:752), so aproject that adds libmdbx via
add_subdirectory()without calling that macro is unaffected. Theflags are still applied to the targets in that case — we see
/experimental:c11atomicson everylibmdbx compile line — so the warnings are emitted on every build; they simply are not fatal.
Suggested fix
For (1), either probe under the conditions the flag is later used in:
or skip the flag for clang-cl, which does not implement it:
The second matches the existing guard at
cmake/compiler.cmake:524.(2) and (3) are source-level and independent of the flag handling.
Workaround
Build a non-
Debugconfiguration.-DMSVC_C11_MAD_ATOMICS=0clears (1) on its own but leaves (2)and (3), so it is not sufficient by itself.