spdlog icon indicating copy to clipboard operation
spdlog copied to clipboard

#3399 broke compatibility with all versions of libfmt prior to 11.2.0

Open Lord-Kamina opened this issue 7 months ago • 7 comments

Here: https://github.com/gabime/spdlog/pull/3399/files#diff-1d7d4c9d189a244df358d2005ee7bfc62368dedfce736cd162ecad07dd399416L28-R28

fmt/base.h does not exist in older versions of libfmt. There should be a check in here.

Lord-Kamina avatar Jun 02 '25 02:06 Lord-Kamina

This could not be done by normal version checks, since FMT_VERSION is defined in fmt/base.h (or previously fmt/core.h) itself.

I would suggest something like:

#if __has_include(<fmt/base.h>)
     #include <fmt/base.h>
#elif __has_include(<fmt/core.h>)
    #include <fmt/core.h>
#else
    #error "no compatible fmtlib header found!"
#endif

FYI, __has_include extension is supported by GCC, Clang and (recent) MSVC.

Harry-Chen avatar Jun 04 '25 14:06 Harry-Chen

Oh, that's nasty.

Maybe I should post about this upstream as well?

Lord-Kamina avatar Jun 04 '25 15:06 Lord-Kamina

__has_include is only cpp 17+

gabime avatar Jun 04 '25 15:06 gabime

@gabime It is standardized in C++17, but was added in GCC / Clang quote a long time ago (at least GCC 5).

Harry-Chen avatar Jun 04 '25 16:06 Harry-Chen

It seems the correct workaround is to just include core.h which was re-added as a stub to include format.h (not sure why not just base.h though)

@gabime It is standardized in C++17, but was added in GCC / Clang quote a long time ago (at least GCC 5).

Yeah, google shows it being present in GCC docs at least as far back as 2012. Still not ideal, but IMO it's either that or blanket including core.h.

Lord-Kamina avatar Jun 04 '25 18:06 Lord-Kamina

Yeah, google shows it being present in GCC docs at least as far back as 2012.

But msvc doesn't offer this in earlier version afaik.

Lets try to ask the fmt author. @vitaut, what would be the recommended fix? to include core.h if fmt version is lower than 11.2.0 ?

gabime avatar Jun 04 '25 19:06 gabime

The code already includes fmt/format.h so including fmt/core.h or fmt/base.h is redundant - those only provide a subset of the API. I suggest simply removing those includes.

vitaut avatar Jun 04 '25 21:06 vitaut