Skip to content

Undefined reference with FMT_HEADER_ONLY and core.h #1296

Closed
@mdcdr

Description

When building with FMT_HEADER_ONLY and including fmt/core.h.

gcc version 9.2.0

$ cat fmt_test.cpp

#include <iostream>
#include <fmt/core.h>

int main()
{
        std::string message = fmt::format("The answer is {}", 42);
        std::cout << message << "\n";
        return 0;
}

$ g++ -o fmt_test -DFMT_HEADER_ONLY -I./include fmt_test.cpp

/usr/bin/ld: /tmp/ccQQn4MB.o: in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > fmt::v6::format<char [17], int, char>(char const (&) [17], int&&)':
fmt_test.cpp:(.text._ZN3fmt2v66formatIA17_cJiEcEENSt7__cxx1112basic_stringIT1_St11char_traitsIS5_ESaIS5_EEERKT_DpOT0_[_ZN3fmt2v66formatIA17_cJiEcEENSt7__cxx1112basic_stringIT1_St11char_traitsIS5_ESaIS5_EEERKT_DpOT0_]+0x70): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > fmt::v6::internal::vformat<char>(fmt::v6::basic_string_view<char>, fmt::v6::basic_format_args<fmt::v6::basic_format_context<std::back_insert_iterator<fmt::v6::internal::buffer<char> >, char> >)'
collect2: error: ld returned 1 exit status

Shouldn't this compile?
If format.h is included instead core.h, it works.
I'm trying to include only core.h, to see if I can reduce executable size.
According to benchmarks executable should be smaller than tinyformat, but it's opposite.

Activity

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

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