odygrd / quill

Asynchronous Low Latency C++ Logging Library
MIT License
1.36k stars 142 forks source link

build FAIL on Windows VS2022 clang-cl #399

Closed tetsuh closed 5 months ago

tetsuh commented 6 months ago

Windows clang-cl build FAIL with the following error. This is introduced in aa8c79d and released in quill v3.4.0.

The reason for the error is that __STDC_LIBEXT1_\ is defined in MSVC but undefined in clang-cl.exe, __STDC_LIBEXT1_\ is undefined both MSVC(cl.exe) and clang-cl.exe environment.

Unfortunately the strnlen() seems incompatible with constexpr in clang-cl compile.

The build will pass with the following changes since MSVC/clang-cl can use the *_s functions anyway. However, this is an ad-hoc modification because the C11 strnlen_s function and the Microsoft strnlen_s function have the same arguments. The same technique for qsort_s() does not work because the arguments are completely different between MSVC and C11.

This change only affects the Windows MSVC/clang-cl build. I will create a PR. Thanks.

diff --git a/quill/include/quill/detail/Serialize.h b/quill/include/quill/detail/Serialize.h
index bf7df29..6b85c28 100644
--- a/quill/include/quill/detail/Serialize.h
+++ b/quill/include/quill/detail/Serialize.h
@@ -29,7 +29,7 @@ namespace detail
 {

 constexpr auto strnlen =
-#ifdef __STDC_LIB_EXT1__
+#if defined(__STDC_LIB_EXT1__) || defined(_MSC_VER)
   ::strnlen_s
 #else
   ::strnlen
> cmake -GNinja ..
-- The C compiler identification is Clang 17.0.3 with MSVC-like command-line
-- The CXX compiler identification is Clang 17.0.3 with MSVC-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
-- CMAKE_BUILD_TYPE: Debug
-- QUILL_VERSION: 3.6.0
-- QUILL_NO_EXCEPTIONS: OFF
-- QUILL_FMT_EXTERNAL: OFF
-- QUILL_NO_THREAD_NAME_SUPPORT: OFF
-- Configuring done (1.8s)
-- Generating done (0.0s)
-- Build files have been written to: D:/gitwork/quill/build

D:\gitwork\quill\build (fix_clangcl_build)
> ninja
[1/200] Building CXX object examples\CMakeFiles\quill_example_custom_clock_advanced.dir\example_custom_clock_advanced.cpp.obj
FAILED: examples/CMakeFiles/quill_example_custom_clock_advanced.dir/example_custom_clock_advanced.cpp.obj
C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\clang-cl.exe  /nologo -TP  -ID:\gitwork\quill\quill\include /DWIN32 /D_WINDOWS /W3 /GR /EHsc /source-charset:utf-8 /execution-charset:utf-8 /MDd /Zi /Ob0 /Od /RTC1 -std:c++17 /showIncludes /Foexamples\CMakeFiles\quill_example_custom_clock_advanced.dir\example_custom_clock_advanced.cpp.obj /Fdexamples\CMakeFiles\quill_example_custom_clock_advanced.dir\ -c -- D:\gitwork\quill\examples\example_custom_clock_advanced.cpp
In file included from D:\gitwork\quill\examples\example_custom_clock_advanced.cpp:1:
In file included from D:\gitwork\quill\quill\include\quill/Quill.h:12:
In file included from D:\gitwork\quill\quill\include\quill/detail/LogMacros.h:10:
In file included from D:\gitwork\quill\quill\include\quill/Logger.h:16:
D:\gitwork\quill\quill\include\quill/detail/Serialize.h(31,16): error: constexpr variable 'strnlen' must be initialized by a constant expression
   31 | constexpr auto strnlen =
      |                ^
   32 | #ifdef __STDC_LIB_EXT1__
   33 |   ::strnlen_s
   34 | #else
   35 |   ::strnlen
      |   ~~~~~~~~~
1 error generated.