Fmt: Wide char strings does not link

Created on 12 Nov 2020  路  3Comments  路  Source: fmtlib/fmt

Given

#include <fmt/core.h>
int main() {
  fmt::format(L"The answer is {}.", 4.2);
}

gcc 10.2.0 (godbolt) with fmt v7.0.0 return the error:

/opt/compiler-explorer/gcc-10.2.0/bin/../lib/gcc/x86_64-linux-gnu/10.2.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/cc2A8WgJ.o: in function `std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > fmt::v6::format<wchar_t [18], double, wchar_t>(wchar_t const (&) [18], double&&)':
/opt/compiler-explorer/libs/fmt/7.0.0/include/fmt/core.h:1832: undefined reference to `std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > fmt::v6::detail::vformat<wchar_t, 0>(fmt::v6::basic_string_view<wchar_t>, fmt::v6::basic_format_args<fmt::v6::basic_format_context<std::back_insert_iterator<fmt::v6::detail::buffer<fmt::v6::type_identity<wchar_t>::type> >, fmt::v6::type_identity<wchar_t>::type> >)'

Visual Studio 2019 16.8.0 with fmt v7.1.2 (built with vcpkg) return the error:

error LNK2019: unresolved external symbol "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl fmt::v7::detail::vformat<wchar_t,0>(class fmt::v7::basic_string_view<wchar_t>,class fmt::v7::basic_format_args<class fmt::v7::basic_format_context<class fmt::v7::detail::buffer_appender<wchar_t>,wchar_t> >)" (??$vformat@_W$0A@@detail@v7@fmt@@YA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@V?$basic_string_view@_W@12@V?$basic_format_args@V?$basic_format_context@V?$buffer_appender@_W@detail@v7@fmt@@_W@v7@fmt@@@12@@Z) referenced in function "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl fmt::v7::format<wchar_t [18],double,wchar_t>(wchar_t const (&)[18],double &&)" (??$format@$$BY0BC@_WN_W@v7@fmt@@YA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@AAY0BC@$$CB_W$$QAN@Z)

But if I add #include <fmt/format.h> the error goes away on gcc, but in Visual Studio I instead get the following errors:

error LNK2019: unresolved external symbol "struct fmt::v7::detail::dragonbox::decimal_fp<float> __cdecl fmt::v7::detail::dragonbox::to_decimal<float>(float)" (??$to_decimal@M@dragonbox@detail@v7@fmt@@YA?AU?$decimal_fp@M@0123@M@Z) referenced in function "class fmt::v7::detail::buffer_appender<wchar_t> __cdecl fmt::v7::detail::write<wchar_t,class fmt::v7::detail::buffer_appender<wchar_t>,float,0>(class fmt::v7::detail::buffer_appender<wchar_t>,float)" (??$write@_WV?$buffer_appender@_W@detail@v7@fmt@@M$0A@@detail@v7@fmt@@YA?AV?$buffer_appender@_W@012@V3012@M@Z)
error LNK2019: unresolved external symbol "struct fmt::v7::detail::dragonbox::decimal_fp<double> __cdecl fmt::v7::detail::dragonbox::to_decimal<double>(double)" (??$to_decimal@N@dragonbox@detail@v7@fmt@@YA?AU?$decimal_fp@N@0123@N@Z) referenced in function "class fmt::v7::detail::buffer_appender<wchar_t> __cdecl fmt::v7::detail::write<wchar_t,class fmt::v7::detail::buffer_appender<wchar_t>,double,0>(class fmt::v7::detail::buffer_appender<wchar_t>,double)" (??$write@_WV?$buffer_appender@_W@detail@v7@fmt@@N$0A@@detail@v7@fmt@@YA?AV?$buffer_appender@_W@012@V3012@N@Z)

Both gcc and Visual Studio works for narrow char strings, and neither need the format.h include.

Is the FMT_API specifier missing for dragonbox::to_decimal?

invalid

Most helpful comment

All 3 comments

You should include fmt/format.h for wide string support (https://fmt.dev/latest/api.html):

fmt/format.h: the full format API providing compile-time format string checks, wide string, output iterator and user-defined type support

The other issue is already reported: #2011.

Was this page helpful?
0 / 5 - 0 ratings