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

Unable to compile spdlog with GCC #2825

Open
sndth opened this issue Jul 21, 2023 · 4 comments
Open

Unable to compile spdlog with GCC #2825

sndth opened this issue Jul 21, 2023 · 4 comments

Comments

@sndth
Copy link

sndth commented Jul 21, 2023

On any GCC version (12/13/14), I cannot compile spdlog. I'm using FreeBSD 12 (x86) and I tried compile simple code, but:

spdlog/fmt/bundled/format.h: In instantiation of 'constexpr int fmt::v9::detail::format_float(Float, int, float_specs, buffer&) [with Float = long double]':
spdlog/fmt/bundled/format.h:3230:25: required from 'constexpr OutputIt fmt::v9::detail::write(OutputIt, T, fmt::v9::basic_format_specs, locale_ref) [with Char = char; OutputIt = fmt::v9::appender; T = long double; typename std::enable_if<std::integral_constant<bool, (std::is_floating_point::value || std::is_same<T, __float128>::value)>::value, int>::type = 0]'
spdlog/fmt/bundled/format.h:3394:25: required from 'constexpr fmt::v9::detail::arg_formatter::iterator fmt::v9::detail::arg_formatter::operator()(T) [with T = long double; Char = char; iterator = fmt::v9::appender]'
spdlog/fmt/bundled/core.h:1649:15: required from 'constexpr decltype (vis(0)) fmt::v9::visit_format_arg(Visitor&&, const basic_format_arg&) [with Visitor = detail::arg_formatter&; Context = basic_format_context<appender, char>; decltype (vis(0)) = appender]'
spdlog/fmt/bundled/format.h:4132:42: required from 'const Char* fmt::v9::detail::vformat_to(buffer&, fmt::v9::basic_string_view, fmt::v9::basic_format_args<fmt::v9::basic_format_context<typename std::conditional<std::is_same<typename fmt::v9::type_identity::type, char>::value, fmt::v9::appender, std::back_insert_iterator<buffer<typename fmt::v9::type_identity::type> > >::type, typename fmt::v9::type_identity::type> >, locale_ref)::format_handler::on_format_specs(int, const Char*, const Char*) [with Char = char]'
spdlog/fmt/bundled/format.h:4135:3: required from 'void fmt::v9::detail::vformat_to(buffer&, fmt::v9::basic_string_view, fmt::v9::basic_format_args<fmt::v9::basic_format_context<typename std::conditional<std::is_same<typename fmt::v9::type_identity::type, char>::value, fmt::v9::appender, std::back_insert_iterator<buffer<typename fmt::v9::type_identity::type> > >::type, typename fmt::v9::type_identity::type> >, locale_ref) [with Char = char; typename std::conditional<std::is_same<typename fmt::v9::type_identity::type, char>::value, fmt::v9::appender, std::back_insert_iterator<buffer<typename fmt::v9::type_identity::type> > >::type = fmt::v9::appender; typename fmt::v9::type_identity::type = char]'
spdlog/fmt/bundled/format-inl.h:1472:21: required from here
spdlog/fmt/bundled/format.h:3122:20: error: invalid use of incomplete type 'struct fmt::v9::detail::dragonbox::float_info<long double, void>'
3122 | const auto f = basic_fp(converted_value);
spdlog/fmt/bundled/format.h:1289:54: note: declaration of 'struct fmt::v9::detail::dragonbox::float_info<long double, void>'
1289 | template <typename T, typename Enable = void> struct float_info;

When I switch compiler to llvm (17), everything compiles well (on Windows also).

CXX_STANDARD 20
spdlog v1.x branch/1.12.0

@tt4g
Copy link
Contributor

tt4g commented Jul 21, 2023

This is fmt library issue and already fixed fmtlib/fmt#3137.
Use bug fixed version (fmt v10.0.0 or avobe).

@sndth
Copy link
Author

sndth commented Jul 21, 2023

Thank you, but - why spdlog doesn't have fixed version?

@tt4g
Copy link
Contributor

tt4g commented Jul 21, 2023

This is because the API is broken because fmt 10 removed the feature to use std::ostream& operator<<(std::ostream&, const T&) instead if fmt::formatter<T> is not defined.
See #2805, fmtlib/fmt#3318 and fmtlib/fmt#2919

However, you can use latest fmt with the CMake variable SPDLOG_FMT_EXTERNAL.

spdlog/CMakeLists.txt

Lines 91 to 92 in d8d23a6

option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
option(SPDLOG_FMT_EXTERNAL_HO "Use external fmt header-only library instead of bundled" OFF)

@jakildev
Copy link

In my build process I set it up like this to use a non-bundled version of fmt and build spdlog with fetchContent, leaving this here in case its useful to anyone:

# fmt (dependency of spdlog)
FetchContent_Declare(fmt
  GIT_REPOSITORY https://github.com/fmtlib/fmt.git
  GIT_TAG master
)
FetchContent_MakeAvailable(fmt)
add_custom_command(
    TARGET IrredenEngineProfiling
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
        ${fmt_BINARY_DIR}/bin/libfmtd.dll
        ${PROJECT_BINARY_DIR}/libfmtd.dll
)

# spdlog
FetchContent_Declare(
    spdlog
    GIT_REPOSITORY https://github.com/gabime/spdlog
    GIT_TAG v1.12.0
)
option(
    IR_SPDLOG_FMT_EXTERNAL
    "Use external fmt library instead of bundled"
    ON
)
FetchContent_GetProperties(spdlog)
if(NOT spdlog_POPULATED)
    FetchContent_Populate(spdlog)
    set(SPDLOG_FMT_EXTERNAL ${IR_SPDLOG_FMT_EXTERNAL})
endif()
add_subdirectory(
    ${spdlog_SOURCE_DIR}
    ${spdlog_BINARY_DIR}
)

target_link_libraries(IrredenEngineProfiling PUBLIC spdlog)
target_include_directories(IrredenEngineProfiling PUBLIC
    ${spdlog_SOURCE_DIR}/include
)

add_custom_command(
    TARGET IrredenEngineProfiling
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
    ${spdlog_BINARY_DIR}/libspdlogd.dll
    ${PROJECT_BINARY_DIR}/libspdlogd.dll
)

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

3 participants