1

我在 Visual Studio 2019 中使用 fmt 7.1.3。

我获取 fmt src 文件并制作一个静态库。

当我将此库链接到执行以下操作的 exe 项目中时:

std::wstring out = fmt::format(L"Answer {}", 42);

它编译但因链接器错误而失败:

未解析的外部符号“类 std::basic_string<wchar_t,struct std::char_traits<wchar_t>,类 std::allocator<wchar_t> > __cdecl fmt::v7::detail::vformat<wchar_t,0>(类 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) 在函数“class std::basic_string”中引用<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl fmt::v7::format<wchar_t [10],int,wchar_t>(wchar_t const (&)[10],整数 &&)"

如果我使用 fmt-6.2.1 中的 src,相同的静态库配置可以正常工作。

谢谢你的帮助。

4

1 回答 1

2

确保包括fmt/format.h定义此函数的位置。引用文档

fmt/format.h:提供编译时格式字符串检查、宽字符串、输出迭代器和用户定义类型支持的完整格式 API

这是一个关于godbolt的工作示例。

于 2020-11-26T22:04:05.823 回答