Skip to content

clang build error with version 8.0: undefined symbol: void ... vformat_to<char>(...) #2377

Description

@jdrouhard

Given the following code:

#include <fmt/format.h>
#include <vector>

void fooImpl(std::vector<char> & chars, fmt::string_view fmt, fmt::format_args args) {
    fmt::vformat_to(std::back_inserter(chars), fmt, args);
}

template <typename S, typename... T>
std::vector<char> foo(const S& s, T &&... args) {
    using namespace fmt;
    std::vector<char> val;
    fooImpl(val, to_string_view(s), make_args_checked<T...>(s, args...));
    return val;
}

int main(int argc, char ** argv) {
    auto chars = foo("testing {}: {}", argc, argv[0]);
    return 0;
}

I get:

ld.lld: error: undefined symbol: void fmt::v7::detail::vformat_to(fmt::v7::detail::buffer&, fmt::v7::basic_string_view, fmt::v7::basic_format_args<fmt::v7::basic_format_context<std::conditional<std::is_same<fmt::v7::type_identity::type, char>::value, fmt::v7::appender, std::back_insert_iterator<fmt::v7::detail::buffer<fmt::v7::type_identity::type> > >::type, fmt::v7::type_identity::type> >, fmt::v7::detail::locale_ref)

Same exact problem with ld and gold, but lld prints the demangled symbol. I know that symbol is defined:

$ nm -C -D libfmt.so.8.0.0
0000000000020d30 W void fmt::v7::detail::vformat_to(fmt::v7::detail::buffer&, fmt::v7::basic_string_view, fmt::v7::basic_format_args<fmt::v7::basic_format_context<std::conditional<std::is_same<fmt::v7::type_identity::type, char>::value, fmt::v7::appender, std::back_insert_iterator<fmt::v7::detail::buffer<fmt::v7::type_identity::type> > >::type, fmt::v7::type_identity::type> >, fmt::v7::detail::locale_ref)

Tested on clang 12 and trunk, using all 3 main linkers (ld, lld, and gold). I'm attempting to link the shared object (not using the header-only version).

GCC 8 and 9 (and presumably 10, 11, and trunk) all seem to handle this fine. clang also works fine with 7.1.3, so it's something new in 8.0.0 that it doesn't like. If it's a clang problem, I'm wondering if there's a workaround? I believe vformat_to<char> was already an extern template with an explicit instantiation in 7.1.3, so I'm not sure what else might be causing this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions