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

error: no matching function for call to 'vformat_to' #2513

Closed
maritalweeping opened this issue Oct 15, 2022 · 4 comments
Closed

error: no matching function for call to 'vformat_to' #2513

maritalweeping opened this issue Oct 15, 2022 · 4 comments

Comments

@maritalweeping
Copy link

I'm building spdlog v1.9.2 from source on ubuntu-jammy using the following command

git clone https://github.com/gabime/spdlog --branch v1.9.2 --single-branch \
&& cd spdlog \
&& mkdir build && cd build \
&& cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/clang++-13\
-DCMAKE_C_COMPILER=/usr/bin/clang-13 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-stdlib=libc++ -std=c++20" \
-DCMAKE_CXX_STANDARD=20 \
-DSPDLOG_BUILD_TESTS=OFF \
&& make -j6 \
&& make install \
&& cd ../.. \
&& rm -rf spdlog

However, I consistently get the following error once I run my code. Strangely, this only seems an issue on linux, since the same code when run using apple-clang on my M1 mac mini runs without complaints.

In file included from /tmp/backtest2/tests/../src/utils/utils.hpp:32:
In file included from /tmp/backtest2/tests/../src/utils/../globals/global_settings.hpp:5:
In file included from /usr/local/include/spdlog/spdlog.h:14:
/usr/local/include/spdlog/logger.h:375:13: error: no matching function for call to 'vformat_to'
            fmt::detail::vformat_to(buf, fmt, fmt::make_format_args(std::forward<Args>(args)...));
            ^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/spdlog/logger.h:90:9: note: in instantiation of function template specialization 'spdlog::logger::log_<unsigned long long &>' requested here
        log_(loc, lvl, fmt, std::forward<Args>(args)...);
        ^
/usr/local/include/spdlog/logger.h:96:9: note: in instantiation of function template specialization 'spdlog::logger::log<unsigned long long &>' requested here
        log(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
        ^
/usr/local/include/spdlog/logger.h:152:9: note: in instantiation of function template specialization 'spdlog::logger::log<unsigned long long &>' requested here
        log(level::debug, fmt, std::forward<Args>(args)...);
        ^
/usr/local/include/spdlog/spdlog.h:155:27: note: in instantiation of function template specialization 'spdlog::logger::debug<unsigned long long &>' requested here
    default_logger_raw()->debug(fmt, std::forward<Args>(args)...);
                          ^
/tmp/jacktest2/tests/../src/utils/utils.hpp:633:21: note: in instantiation of function template specialization 'spdlog::debug<unsigned long long &>' requested here
            spdlog::debug("Generating a sequence of {} strategy parameters.", n);
                    ^
/usr/local/include/fmt/format.h:4135:6: note: candidate template ignored: could not match 'basic_format_args' against 'format_arg_store'
void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
     ^
In file included from /tmp/backtest2/tests/structprint_tests.cpp:4:
In file included from /tmp/backtest2/tests/../src/utils/structprint.hpp:9:
In file included from /tmp/backtest2/tests/../src/utils/utils.hpp:32:
In file included from /tmp/backtest2/tests/../src/utils/../globals/global_settings.hpp:5:
In file included from /usr/local/include/spdlog/spdlog.h:14:
/usr/local/include/spdlog/logger.h:375:13: error: no matching function for call to 'vformat_to'
            fmt::detail::vformat_to(buf, fmt, fmt::make_format_args(std::forward<Args>(args)...));
            ^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/spdlog/logger.h:90:9: note: in instantiation of function template specialization 'spdlog::logger::log_<unsigned long long &, unsigned long long &, double &>' requested here
        log_(loc, lvl, fmt, std::forward<Args>(args)...);
        ^
/usr/local/include/spdlog/logger.h:96:9: note: in instantiation of function template specialization 'spdlog::logger::log<unsigned long long &, unsigned long long &, double &>' requested here
        log(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
        ^
/usr/local/include/spdlog/logger.h:152:9: note: in instantiation of function template specialization 'spdlog::logger::log<unsigned long long &, unsigned long long &, double &>' requested here
        log(level::debug, fmt, std::forward<Args>(args)...);
        ^
/usr/local/include/spdlog/spdlog.h:155:27: note: in instantiation of function template specialization 'spdlog::logger::debug<unsigned long long &, unsigned long long &, double &>' requested here
    default_logger_raw()->debug(fmt, std::forward<Args>(args)...);
                          ^
/tmp/jacktest2/tests/../src/utils/utils.hpp:655:21: note: in instantiation of function template specialization 'spdlog::debug<unsigned long long &, unsigned long long &, double &>' requested here
            spdlog::debug("n: {}, remaining: {}, throughput: {}", n, num_iterations, thp);
                    ^
/usr/local/include/fmt/format.h:4135:6: note: candidate template ignored: could not match 'basic_format_args' against 'format_arg_store'
void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
     ^
2 errors generated.
ninja: build stopped: subcommand failed.

@tt4g
Copy link
Contributor

tt4g commented Oct 15, 2022

I can't be sure since you did not provide the source code of your project, but from the error message it is due to a failure to resolve a template function.

By name, num_iterations is an iterator object.
The iterator cannot be formatted as is, so replace it with fmt::join(num_iterations).
See: https://fmt.dev/latest/api.html#_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view

@maritalweeping
Copy link
Author

maritalweeping commented Oct 16, 2022

Thanks for your input @tt4g . Unfortunately, the variable num_iterations is a double, and the last template parameter in spdlog::logger::debug<unsigned long long &, unsigned long long &, double &>.

Given that all the variables n, num_iterations, thp are simple, numeric built-in types, I can't seem to fathom why spdlog wouldn't accept a variadic template pack without the explicit specification of its types in this case. After all, isn't it the raison d'etre of spdlog anyway?

@tt4g
Copy link
Contributor

tt4g commented Oct 16, 2022

Is /usr/local/include/fmt an external fmt library?
Looking at the command when spdlog was built, SPDLOG_FMT_EXTERNAL is not defined, so spdlog is configured to use the bundled fmt.
The bundled fmt should be installed in /usr/local/include/spdlog/fmt/bundled/.

spdlog/CMakeLists.txt

Lines 306 to 307 in d011332

install(DIRECTORY include/${PROJECT_NAME}/fmt/bundled/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/fmt/bundled/")

My guess is that the fmt installed on your machine is being used.
And I think that fmt is version 9 or above.

spdlog 1.9.2 does not support fmt 9.x.
See #2485.

@maritalweeping
Copy link
Author

Thanks a ton @tt4g . Indeed it was the fact that v1.9.2 was seeing previous installations of fmt v9.x.x elsewhere on my system. Sticking to the compatible version of fmt fixed the issue.

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