-
I am using spdlog via vcpkg on Windows. I was a bit confused when the set_default_logger did not apply over the library boundary. The documentation mentions the header only version of sdllog and a workaround; but this applies also to the shared library version. Even if I explicitly set SPDLOG_COMPILED_LIB and SPDLOG_SHARED_LIB I get the behavior. It appears that default_logger_raw and details::registry::instance() always get inlined no matter what. I am not sure, but this seems to be a deliberate choice to ensure compatibility to the header only version. Although I find that rather annoying I have a workaround; I wrote macros that wrap spdlog anyway so that I can capture the location and then I just added my own global reference that I can read and write via function in the DLL. Is this behavior intentional? Is this a bug? or am I just incompetent to build and link against spdlog properly? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
This is due to the spdlog design and the C++ language specification. Since support for the header-only library is still in place, spdlog keeps default loggers and logger registry in variables with the And in the C++ language specification, With this specification, the default logger variables accessed when spdlog is built as a shared library and the default logger variables accessed by applications linked with spdlog (shared library) refer to different memory. The way to access the default logger in the shared library from your application (as you have done) is to have a published function in the shared library that accesses the default logger. See also: |
Beta Was this translation helpful? Give feedback.
-
Which single line of code would fix this? (need to work on windows&linux and in shared/static/header-only configurations) |
Beta Was this translation helpful? Give feedback.
-
No problem, its all good. I am really trying to understand how this can be fixed in a single line of code. Would be very helpful (regardless the question of of backward compatibility). |
Beta Was this translation helpful? Give feedback.
This is due to the spdlog design and the C++ language specification.
spdlog was previously header-only library, but with version 1.4.0, static library and shared library build support has been added.
Since support for the header-only library is still in place, spdlog keeps default loggers and logger registry in variables with the
static
keyword in order to manage the global state.And in the C++ language specification,
static
variables are placed in dedicated memory storage on a per-build basis (libraries, executables).With this specification, the default logger variables accessed when spdlog is built as a shared library and the default logger variables accessed by applications linked wi…