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

Including spdlog after fmt throws an error: no member named 'basic_runtime' in namespace 'fmt', but the reverse is fine #2614

Closed
GavinRay97 opened this issue Jan 19, 2023 · 4 comments

Comments

@GavinRay97
Copy link

Reproduction:

project(example)
cmake_minimum_required(VERSION 3.20)

Include(FetchContent)
FetchContent_Declare(
    fmt
    GIT_REPOSITORY https://github.com/fmtlib/fmt
    GIT_TAG        master
)
FetchContent_MakeAvailable(fmt)
FetchContent_Declare(
    spdlog
    GIT_REPOSITORY https://github.com/gabime/spdlog
    GIT_TAG        v1.11.0
)
FetchContent_MakeAvailable(spdlog)

file(GLOB_RECURSE SOURCES "src/*.cpp")
add_executable(example ${SOURCES})
target_link_libraries(example
    PRIVATE
        fmt::fmt
        spdlog::spdlog
)
#include <fmt/format.h>
#include <spdlog/spdlog.h> // Error here

int main() { return 0; }
@tt4g
Copy link
Contributor

tt4g commented Jan 19, 2023

To use an external fmt library, you must define CMake variable SPDLOG_FMT_EXTERNAL (or SPDLOG_FMT_EXTERNAL_HQ).

spdlog/CMakeLists.txt

Lines 88 to 89 in 654dbc5

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)

@GavinRay97
Copy link
Author

GavinRay97 commented Jan 19, 2023

Ah whoops, my apologies, sorry for cluttering the issues!

EDIT: This still appears to be an issue even after setting the CMake variable, I have done:

set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "Use external fmt library" FORCE)

# ... fetchcontent stuff
FetchContent_Declare(
    spdlog
    GIT_REPOSITORY https://github.com/gabime/spdlog
    GIT_TAG        v1.11.0
)
FetchContent_MakeAvailable(spdlog)
[build] [7/9] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/spdlog.cpp.o
[build] FAILED: _deps/spdlog-build/CMakeFiles/spdlog.dir/src/spdlog.cpp.o 
[build] ccache /home/user/projects/llvm-project/build/bin/clang++ -DSPDLOG_COMPILED_LIB -DSPDLOG_FMT_EXTERNAL -I/home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include -I/home/user/projects/bustub-cpp-v2/build/sanitize/_deps/fmt-src/include -g -fcolor-diagnostics -std=c++2b -MD -MT _deps/spdlog-build/CMakeFiles/spdlog.dir/src/spdlog.cpp.o -MF _deps/spdlog-build/CMakeFiles/spdlog.dir/src/spdlog.cpp.o.d -o _deps/spdlog-build/CMakeFiles/spdlog.dir/src/spdlog.cpp.o -c /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/src/spdlog.cpp
[build] In file included from /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/src/spdlog.cpp:8:
[build] In file included from /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include/spdlog/spdlog-inl.h:7:
[build] In file included from /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include/spdlog/spdlog.h:12:
[build] /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include/spdlog/common.h:168:111: error: no member named 'basic_runtime' in namespace 'fmt'
[build]           std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value>
[build]                                                                                                          ~~~~~^
[build] /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include/spdlog/common.h:168:125: error: 'Char' does not refer to a value
[build]           std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value>
[build]                                                                                                                             ^
[build] /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include/spdlog/common.h:165:25: note: declared here
[build] template<class T, class Char = char>
[build]                         ^
[build] /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include/spdlog/common.h:168:130: error: expected '(' for function-style cast or type construction
[build]           std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value>
[build]                                                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
[build] /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include/spdlog/common.h:168:133: error: expected class name
[build]           std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value>
[build]                                                                                                                                     ^
[build] /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include/spdlog/common.h:188:123: error: no member named 'value' in 'spdlog::is_convertible_to_basic_format_string<const fmt::basic_string_view<char> &>'
[build] struct is_convertible_to_any_format_string : std::integral_constant<bool, is_convertible_to_basic_format_string<T, char>::value ||
[build]                                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
[build] /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include/spdlog/logger.h:106:48: note: in instantiation of template class 'spdlog::is_convertible_to_any_format_string<const fmt::basic_string_view<char> &>' requested here
[build]     template<class T, typename std::enable_if<!is_convertible_to_any_format_string<const T &>::value, int>::type = 0>
[build]                                                ^
[build] /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include/spdlog/logger.h:107:10: note: while substituting prior template arguments into non-type template parameter [with T = string_view_t]
[build]     void log(source_loc loc, level::level_enum lvl, const T &msg)
[build]          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build] /home/user/projects/bustub-cpp-v2/build/sanitize/_deps/spdlog-src/include/spdlog/logger.h:140:9: note: while substituting deduced template arguments into function template 'log' [with T = string_view_t, $1 = (no value)]
[build]         log(source_loc{}, lvl, msg);
[build]         ^
[build] 5 errors generated.

@tt4g
Copy link
Contributor

tt4g commented Jan 19, 2023

The fmt bundled with spdlog v1.11.0 is version 9.1.0.
This version was released on 2022-08-28 (https://github.com/fmtlib/fmt/releases/tag/9.1.0).

If the latest fmt source code has incompatible changes, spdlog is not guaranteed to work.

EDIT: fmt::basic_runtime has been removed from fmtlib/fmt@3a5e19f (this change not released yet).

@GavinRay97
Copy link
Author

Ahh okay, thank you!

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