diff --git a/include/fmt/core.h b/include/fmt/core.h index 5f44a9748e46..9899f902b879 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -960,6 +960,14 @@ template class buffer { } }; +#if FMT_MSC_VERSION +# ifdef FMT_EXPORT +extern template class buffer; +# else +template class FMT_API buffer; +# endif +#endif + struct buffer_traits { explicit buffer_traits(size_t) {} auto count() const -> size_t { return 0; } diff --git a/src/format.cc b/src/format.cc index 19dff44419e1..1e7bbc98acaa 100644 --- a/src/format.cc +++ b/src/format.cc @@ -22,6 +22,13 @@ template FMT_API auto locale_ref::get() const -> std::locale; // Explicit instantiations for char. +#if FMT_MSC_VERSION +// fmt::ostream does it implicitly, so we need make it explicitly. +// Otherwise we get ODR violation when {fmt} is built as a shared library +// and fmt/os.h is not included by the user. +template class FMT_API buffer; +#endif + template FMT_API auto thousands_sep_impl(locale_ref) -> thousands_sep_result; template FMT_API auto decimal_point_impl(locale_ref) -> char;