-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash on Windows x64 in spdlog_ex constructor #2902
Comments
C++ will not work properly if debug and release builds are mixed. Please unify only debug and release builds. |
Thanks for the response. Can't link a Release (that is - Release w/o debug info) build of my application (because of some unrelated issue), but don't think I'm mixing Debug and any kind of Release binaries |
Since the error is occurring in the following code, the build mode (Relase/Debug) of spdlog/include/spdlog/common-inl.h Lines 50 to 58 in 508d20f
I don't know what you think, but if C++ debugging information is enabled, additional variables are allocated in STL. Furthermore, Visual Studio has different C++ runtime libraries that are linked depending on the build mode, so libraries built with incompatible build modes cannot even be linked together (I assume this is the reason you cannot link in your release builds). Where did you get See also: https://stackoverflow.com/questions/11658915/mixing-debug-and-release-library-binary-bad-practice |
Yes, both |
Hi, @ezemskov, @tt4g and @gabime I get a similar crash on Windows x64 with latest VS2022 (17.10.3), and I searched in existing issues, and this issue is perhaps the most relevant one. Minimal Reproduce StepsVisual Studio VersionGet codeGet latest code of spdlog: git clone ssh://[email protected]/gabime/spdlog which is the latest commit of branch commit c3aed4b68373955e1cc94307683d44dca1515d2b (HEAD -> v1.x, origin/v1.x, origin/HEAD)
Author: Dominik Grabiec <[email protected]>
Date: Tue May 21 23:20:17 2024 +0200
Add wide character formatting and output support to wincolor_sink. (#3092)
Fixes printing of unicode characters to the windows console such as microsecond suffix for std::chrono types. buildThen build it with commands: cd spdlog
cmake -S . -B build -G "Visual Studio 17 2022" -A x64 then open #include <spdlog/spdlog.h>
int main()
{
SPDLOG_INFO("x");
return 0;
} Ensure the configuration type is Then it just run and crash: Configuration typesI can reproduce only in The previous message by @tt4g, mentions
I know there is And in my understanding, the
I'm not sure if the aforementioned "additional allocated variables in STL" is the same as |
@zchrissirhcz This command builds spdlog with If you are going to release build an application, you must also release build spdlog.
|
@tt4g That it to say,
In the CMake document, https://cmake.org/cmake/help/latest/prop_gbl/GENERATOR_IS_MULTI_CONFIG.html , Visual Studio generators are marked as Multi-Config generators. For my reproduce case, I built it in Visual Studio, there is no other dependencies. the bug reproduce when I choose Could you please give an example that "additional variables are allocated in STL" ? @tt4g |
@zchrissirhcz I don't remember the comment "additional variables are allocated in STL", it is well known that in debug builds additional symbols are added to allow debugging. However, it is Microsoft that maintains the STL for MSVC. We do not know the exact specifications of the STL. A search for |
@zchrissirhcz I just noticed that |
@tt4g Thanks for the link https://stackoverflow.com/a/31810986 . Now I know what that means. I did not check (I follow the steps in https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-history#uninstalling-visual-studio-to-go-back-to-an-earlier-release to uninstall-reinstall) |
I'm not familiar with |
@zchrissirhcz Probably the same problem as this issue: microsoft/STL#4730 #include <iostream>
#include <mutex>
std::mutex mtx;
void testmethod() {
std::scoped_lock lock{ mtx };
std::cout << "lock worked!\n";
}
int main()
{
std::cout << "Start!\n";
testmethod();
std::cout << "End!\n";
return 0;
} |
@tt4g Thanks for the reference link microsoft/STL#4730 and code. C++17To be precise, C++17 is required, i.e. in CMakeLists.txt: set(CMAKE_CXX_STANDARD 17) This solves the compile errors:
VS2022 17.9.7 ResultReleaseC:\work\dbg\x\build>.\Release\testbed.exe
Start!
lock worked!
End! DebugC:\work\dbg\x\build>.\Debug\testbed.exe
Start!
lock worked!
End! VS2022 17.10.3 Result
VS2022 17.10.3, the "End!" is not printed. Steps: C:\work\dbg\y>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33811 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
cd C:\work\dbg\y
C:\work\dbg\vim ConsoleApplication5.cpp
C:\work\dbg\y>mkdir x64
C:\work\dbg\y>cd x64
C:\work\dbg\y\x64>mkdir Release
C:\work\dbg\y\x64>cd ..
cl /c /Zi /W3 /WX- /diagnostics:column /sdl /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++17 /permissive- /Fo"x64\Release\\" /Fd"x64\Release\vc143.pdb" /external:W3 /Gd /TP /FC /errorReport:prompt ConsoleApplication5.cpp
link x64\Release\ConsoleApplication5.obj Output:
|
So, let me do a short conclusion:
add_compile_definitions(_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
|
From the side of STL implementation and spdlog implementation:
|
This problem does not seem to occur if the Microsoft Visual C++ 2015-2022 Redistributable package and toolset is up-to-date, even if it is Visual Studio version 17.10.0 or later. |
@tt4g Thanks for the link https://stackoverflow.com/questions/78598141/first-stdmutexlock-crashes-in-application-built-with-latest-visual-studio/78599923#78599923 . After a repair of the vc redist package and a Windows reboot, it solved. Let me do a short conclusion again:
PS C:\work\dbg\x\build2> echo ((Get-Command vcruntime140.dll).Path)
C:\Windows\system32\vcruntime140.dll
PS C:\work\dbg\x\build2> echo ((Get-Command vcruntime140.dll).Version)
Major Minor Build Revision
----- ----- ----- --------
14 40 33810 0
|
Hi Gabi,
We're using spdlog 1.11.0 with external libfmt 1.9.0, on Windows with VS2019 (v142 toolchain, x64 build)
If the file configured for a filesink is no write-accessible, spdlog release build would crash (on access violation ?), inside
fmt::v9::format_system_error(...)
calldebug build would throw a
spdlog::spdlog_ex
exception successfully (although,spdlog_ex::what()
would return garbage)Replacing lines 62-63 from
spdlog\common-inl.h
(that is,format_system_error(...)
call) with following workarounds the issue.msg_ = msg;
Stack trace and caller code are below
The text was updated successfully, but these errors were encountered: