fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
20.74k stars 2.49k forks source link

Linkage errors on Mac OS clang with FMT_HEADER_ONLY #3505

Closed SlavaC1 closed 1 year ago

SlavaC1 commented 1 year ago

I'm getting following errors when building on Mac with XCode for M1 and x86_64:

Undefined symbols for architecture arm64:
  "char fmt::v9::detail::decimal_point_impl<char>(fmt::v9::detail::locale_ref)", referenced from:
      fmt::v9::appender fmt::v9::detail::do_write_float<fmt::v9::appender, fmt::v9::detail::dragonbox::decimal_fp<float>, char, fmt::v9::detail::digit_grouping<char> >(fmt::v9::appender, fmt::v9::detail::dragonbox::decimal_fp<float> const&, fmt::v9::basic_format_specs<char> const&, fmt::v9::detail::float_specs, fmt::v9::detail::locale_ref) in PreferencesPanelController.o
      fmt::v9::appender fmt::v9::detail::do_write_float<fmt::v9::appender, fmt::v9::detail::dragonbox::decimal_fp<double>, char, fmt::v9::detail::digit_grouping<char> >(fmt::v9::appender, fmt::v9::detail::dragonbox::decimal_fp<double> const&, fmt::v9::basic_format_specs<char> const&, fmt::v9::detail::float_specs, fmt::v9::detail::locale_ref) in PreferencesPanelController.o
      fmt::v9::appender fmt::v9::detail::do_write_float<fmt::v9::appender, fmt::v9::detail::big_decimal_fp, char, fmt::v9::detail::digit_grouping<char> >(fmt::v9::appender, fmt::v9::detail::big_decimal_fp const&, fmt::v9::basic_format_specs<char> const&, fmt::v9::detail::float_specs, fmt::v9::detail::locale_ref) in PreferencesPanelController.o
  "fmt::v9::vformat(fmt::v9::basic_string_view<char>, fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender, char> >)", referenced from:
      spdlog::logger::sink_it_(spdlog::details::log_msg const&) in PreferencesPanelController.o
      void spdlog::logger::log_<char const*>(spdlog::source_loc, spdlog::level::level_enum, fmt::v9::basic_string_view<char>, char const*&&) in PreferencesPanelController.o
      spdlog::async_logger::backend_sink_it_(spdlog::details::log_msg const&) in PreferencesPlugin.o
      spdlog::sinks::rotating_file_sink<std::__1::mutex>::calc_filename(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long) in PreferencesPlugin.o
      void spdlog::logger::log_<char const*, unsigned long&>(spdlog::source_loc, spdlog::level::level_enum, fmt::v9::basic_string_view<char>, char const*&&, unsigned long&) in libCore.a(UTF8String.o)
  "fmt::v9::detail::thousands_sep_result<char> fmt::v9::detail::thousands_sep_impl<char>(fmt::v9::detail::locale_ref)", referenced from:
      fmt::v9::detail::digit_grouping<char>::digit_grouping(fmt::v9::detail::locale_ref, bool) in PreferencesPanelController.o

      Undefined symbols for architecture x86_64:
  "char fmt::v9::detail::decimal_point_impl<char>(fmt::v9::detail::locale_ref)", referenced from:
      fmt::v9::appender fmt::v9::detail::do_write_float<fmt::v9::appender, fmt::v9::detail::dragonbox::decimal_fp<float>, char, fmt::v9::detail::digit_grouping<char> >(fmt::v9::appender, fmt::v9::detail::dragonbox::decimal_fp<float> const&, fmt::v9::basic_format_specs<char> const&, fmt::v9::detail::float_specs, fmt::v9::detail::locale_ref) in PreferencesPanelController.o
      fmt::v9::appender fmt::v9::detail::do_write_float<fmt::v9::appender, fmt::v9::detail::dragonbox::decimal_fp<double>, char, fmt::v9::detail::digit_grouping<char> >(fmt::v9::appender, fmt::v9::detail::dragonbox::decimal_fp<double> const&, fmt::v9::basic_format_specs<char> const&, fmt::v9::detail::float_specs, fmt::v9::detail::locale_ref) in PreferencesPanelController.o
      fmt::v9::appender fmt::v9::detail::do_write_float<fmt::v9::appender, fmt::v9::detail::big_decimal_fp, char, fmt::v9::detail::digit_grouping<char> >(fmt::v9::appender, fmt::v9::detail::big_decimal_fp const&, fmt::v9::basic_format_specs<char> const&, fmt::v9::detail::float_specs, fmt::v9::detail::locale_ref) in PreferencesPanelController.o
  "fmt::v9::vformat(fmt::v9::basic_string_view<char>, fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender, char> >)", referenced from:
      spdlog::logger::sink_it_(spdlog::details::log_msg const&) in PreferencesPanelController.o
      void spdlog::logger::log_<char const*>(spdlog::source_loc, spdlog::level::level_enum, fmt::v9::basic_string_view<char>, char const*&&) in PreferencesPanelController.o
      spdlog::async_logger::backend_sink_it_(spdlog::details::log_msg const&) in PreferencesPlugin.o
      spdlog::sinks::rotating_file_sink<std::__1::mutex>::calc_filename(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long) in PreferencesPlugin.o
      void spdlog::logger::log_<char const*, unsigned long&>(spdlog::source_loc, spdlog::level::level_enum, fmt::v9::basic_string_view<char>, char const*&&, unsigned long&) in libCore.a(UTF8String.o)
      void spdlog::logger::log_<char const*, char const*>(spdlog::source_loc, spdlog::level::level_enum, fmt::v9::basic_string_view<char>, char const*&&, char const*&&) in libCore.a(PathUtils.o)
ld: symbol(s) not found for architecture x86_64
vitaut commented 1 year ago

The first symbols is defined in https://github.com/fmtlib/fmt/blob/13156e54bf91e44641ce3aac041d31f9a15a8042/include/fmt/format-inl.h#L101

and similarly for other symbols. Please provide a repro, ideally on godbolt.

SlavaC1 commented 1 year ago

Thanks for the reply. I saw the file you've mentioned, but wanted to understand some concepts to make sure I'm not missing something.

I intent to use fmt bundled with spdlog as part of spdlog. I intent to use it "headers only", in my understanding no cpp files need to be included in the project or compiled. I just need to include the headers like so:

#define SPDLOG_HEADER_ONLY
#define FMT_HEADER_ONLY

#include <spdlog/common.h>
#include <spdlog/spdlog.h>
#include <spdlog/async.h>
#include <spdlog/logger.h>
#include <spdlog/fmt/xchar.h>
#include <spdlog/fmt/bundled/printf.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>

On Windows x64 everything compiles and runs without problems. On Mac unfortunately, I'm getting the errors above when compiling with XCode 13 for arm64 and x64.

Can't provide a repo unfortunately because our project is not on github.

vitaut commented 1 year ago

I wasn't able to repro the issue on Mac and not familiar with spdlog bundling mechanism to comment whether you are using it correctly.