Skip to content
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

compile error on Windows with external fmtlib and MSVC 17.3.6 #2512

Closed
YunchengLiu opened this issue Oct 15, 2022 · 1 comment
Closed

compile error on Windows with external fmtlib and MSVC 17.3.6 #2512

YunchengLiu opened this issue Oct 15, 2022 · 1 comment

Comments

@YunchengLiu
Copy link
Contributor

YunchengLiu commented Oct 15, 2022

Thanks a lot for this excellent library, helped me a lot.
But I encountered a sudden problem.
On Windows platform, after enabling wchar_t and external fmtlib support in spdlog, when compiling with C++20 option in MSVC 17.3.6, fmt throws a compilation error.

spdlog ( 1.10.0#1) and fmtlib (9.1.0) are all installed via vcpkg(x64-windows) with lasted port comfigurations.

Message as follows:

Error C7595: "fmt:: v9:: basic_format_string<wchar_t, const tm&>:: basic_format_string": The call to an instant function is not a constant expression.

The wrong location is:

return fmt::format(fmt_filename, now_tm);

I saw the comments here, but I still tried to modify it to fmt::runtime , it compiles successfully at this time, it seems that the comments here are a bit outdated? Has the new version of MSVC resolved the contradiction between wchar_t and fmt?

I tried to reproduce the above problem externally with the following minimal code. On my local PC, the following code using MSVC 17.3.6 will throw the same error (not modified to fmt::runtime ).

#define SPDLOG_WCHAR_FILENAMES
#define SPDLOG_FMT_EXTERNAL
#include <fmt/format.h>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/daily_file_sink.h>

int main(){

    auto logger = spdlog::daily_logger_mt("daily_logger", L"logs/daily.txt", 2, 30);

    logger->info("{} world", "hello");

}

Since I don't know about other platforms and the specific requirements for compiler versions, I would like to ask if it is possible to modify this to fmt::runtime to solve the problem?

@YunchengLiu YunchengLiu changed the title compile error on Windows wiht external fmtlib compile error on Windows with external fmtlib and MSVC 17.3.6 Oct 15, 2022
@tt4g
Copy link
Contributor

tt4g commented Oct 15, 2022

fmt recently added support for wcart_t * compilation time checks (fmtlib/fmt#3107 (comment)).

The fmt bundled with spdlog is version 8.x, so it does not take into account the compile check feature of the latest version.

Can you add the SPDLOG_FMT_RUNTIME macro to avoid the problem?
Also, if it works, could you please create a PR?

# if defined(_MSC_VER) && defined(SPDLOG_WCHAR_FILENAMES) // for some reason msvc doesn't allow fmt::runtime(..) with wchar here
return fmt::format(fmt_filename, now_tm);
# else
return fmt::format(SPDLOG_FMT_RUNTIME(fmt_filename), now_tm);
# endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants