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

new Visual Studio v16.10 breaks existing spdlog library #1955

Closed
gamagan opened this issue May 25, 2021 · 18 comments
Closed

new Visual Studio v16.10 breaks existing spdlog library #1955

gamagan opened this issue May 25, 2021 · 18 comments

Comments

@gamagan
Copy link

gamagan commented May 25, 2021

I have spdlog version 1.8.1

I made the mistake of upgrading from Visual Studio 16.9 to 16.10, and it broke my code. I get errors from spdlog library.

spdlog/fmt/bundled/format.h(3510,29): error C2668: 'fmt::v7::make_format_args': ambiguous call to overloaded function

spdlog/fmt/bundled/core.h(1424,43): message : could be 'fmt::v7::format_arg_store<context,MyType,_Ty> fmt::v7::make_format_args<context,MyType,_Ty>(const MyType &,const _Ty &)

or 'auto std::make_format_args<context,MyType,_Ty>(const MyType &,const _Ty &)

Any idea how I can get around this issue?

@tt4g
Copy link
Contributor

tt4g commented May 26, 2021

Was the error reported when you built your project?
From the error message it is not possible to distinguish if the problem is caused by your project code calling fmt through spdlog, or if there is a problem with the spdlog project itself.

@tt4g
Copy link
Contributor

tt4g commented May 26, 2021

It seems that already fixed fmtlib/fmt#2295.
Should you external fmt library to solve this problem.

@damienhocking
Copy link

damienhocking commented May 26, 2021

<format> is now part of VS 16.10

@janclod
Copy link

janclod commented Jun 14, 2021

Hi, I am quite newbie so please take this into account while reading my comment.

I am experiencing and suffering form this issue on my own project. As far as I understand the closest solution is to include the latest fix (fmtlib/fmt#2295) of the fmt library into spdlog. Is this correct? Do you have any other suggestions?

@tt4g
Copy link
Contributor

tt4g commented Jun 14, 2021

@janclod Please replace the bundled fmt yourself.

Another way is to build fmt as an external library, and set the CMake variable SPDLOG_FMT_EXTERNAL or SPDLOG_FMT_EXTERNAL_HQ to ON when you build spdlog with cmake.

spdlog/CMakeLists.txt

Lines 176 to 196 in 100f300

# ---------------------------------------------------------------------------------------
# Use fmt package if using external fmt
# ---------------------------------------------------------------------------------------
if(SPDLOG_FMT_EXTERNAL OR SPDLOG_FMT_EXTERNAL_HO)
if(NOT TARGET fmt::fmt)
find_package(fmt CONFIG REQUIRED)
endif()
target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL)
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL)
# use external fmt-header-nly
if(SPDLOG_FMT_EXTERNAL_HO)
target_link_libraries(spdlog PUBLIC fmt::fmt-header-only)
target_link_libraries(spdlog_header_only INTERFACE fmt::fmt-header-only)
else() # use external compile fmt
target_link_libraries(spdlog PUBLIC fmt::fmt)
target_link_libraries(spdlog_header_only INTERFACE fmt::fmt)
endif()
set(PKG_CONFIG_REQUIRES fmt) # add dependency to pkg-config
endif()

@janclod
Copy link

janclod commented Jun 14, 2021

Hi tt4g, thanks for your reply. I believe that I tried something like this here: https://github.com/janclod/spdlog/tree/v1.8.1-alfa.

Is this what you mean? Simply copy-pasting the files from the fmt project into the bundled folder?

@tt4g
Copy link
Contributor

tt4g commented Jun 14, 2021

@janclod Right, you need to replace the fmt source with the latest version.

@janclod
Copy link

janclod commented Jun 14, 2021

@tt4g thanks, I will give it a try :)

@janclod
Copy link

janclod commented Jun 14, 2021

@tt4g I do get an error when building

'void fmt::v7::format_system_error(fmt::v7::detail::buffer<char> &,int,const char *) noexcept': cannot convert argument 3 from 'const std::string' to 'const char *'	spdlog	C:\Users\ClaudioTiecher\source\repos\Version7\image_saver\external\xb-deps\xb-deps\janclod\spdlog\v1.8.1-alfa\include\spdlog\common-inl.h	59	

@tt4g
Copy link
Contributor

tt4g commented Jun 14, 2021

@janclod This is known issue, fmt API has been changed in the latest release.
Look this comment: #1941 (comment)

And you can fix it with the following changes.

include/spdlog/common-inl.h line 56:

SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno)
{
    memory_buf_t outbuf;
-    fmt::format_system_error(outbuf, last_errno, msg);
+    fmt::format_system_error(outbuf, last_errno, msg.c_str());
    msg_ = fmt::to_string(outbuf);
}

@janclod
Copy link

janclod commented Jun 14, 2021

@tt4g thanks again for pointing me in the right direction, I am still getting more errors, I will first try to go through them myself and come back here if I need help.

@janclod
Copy link

janclod commented Jun 14, 2021

@tt4g I am totally lost due to my lack of knowledge in C++, would you be able to help further?

'basic_data': looks like a function definition, but there is no parameter list; skipping apparent body	spdlog	C:\Users\ClaudioTiecher\source\repos\Version7\image_saver\external\xb-deps\xb-deps\janclod\spdlog\v1.8.1-alfa\src\fmt.cpp	61	

@tt4g
Copy link
Contributor

tt4g commented Jun 14, 2021

@janclod spdlog/src/fmt.cpp has also been copied from the fmt library. Since this file doesn't seem to be updated in the your forked repository, you need to copy fmt.cpp from fmt repository.

@janclod
Copy link

janclod commented Jun 14, 2021

@tt4g it looks like the fmt.cpp file is not there any longer. Any suggestion?

@tt4g
Copy link
Contributor

tt4g commented Jun 14, 2021

@janclod Sorry, I checked the fmt repository and it seems that src/format.cc is renamed to spdlog/src/fmt.cpp.
It was written at the top of spdlog/src/fmt.cpp:
https://github.com/gabime/spdlog/blob/v1.8.5/src/fmt.cpp#L1

After copying src/format.cc, don't forget to add the spdlog macros at the beginning and end.

Example:

// Copyright  here!

#ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif

#if !defined(SPDLOG_FMT_EXTERNAL)
#include <spdlog/fmt/bundled/format-inl.h>

// `src/format.cc` contents here!

#endif // !SPDLOG_FMT_EXTERNAL

@janclod
Copy link

janclod commented Jun 14, 2021

@tt4g no worries, you have been very helpful :)

I manage to build successfully! :D

@janclod
Copy link

janclod commented Jun 15, 2021

@tt4g if I can contribute in any way, please let me know. I thought that it could be helpful to have my fork available for people facing this issue, maybe as a sort of temporary fix?

@tt4g
Copy link
Contributor

tt4g commented Jun 15, 2021

@janclod When the next version of fmt is released, you can create a pull request (close #1941) to replace the fmt that spdlog bundles with the latest version.

Unfortunately, fmt has not been released since version 7.1.3 (which is the version that spdlog is bundled with), so you won't be able to create a pull request for a while.
However, don't worry about it, someone will work on the upgrade.

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

5 participants