首页 > 解决方案 > 无法使用 g++9.2.1 编译 fmt/format.h

问题描述

我正在尝试从 Packt 的C++20视频系列中编译示例代码。它使用 <fmt/format.h>,我是这样安装的:sudo apt install libfmt-dev. (我很乐意使用 C++20 的版本,但我认为 g++ 还没有。)

我在 Ubuntu 9.10 上;g++ 版本是g++ (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008.

这是编译目标文件的命令。

g++ -g -o example_1.o -c -std=gnu++17 -I../common -I../external/include example_1.cpp

它似乎工作。(我没有使用存储库附带的 Makefile 等,因为它们甚至没有达到这个程度。)这是链接的命令:

g++ -g -o example_1.out -std=gnu++17 -lfmt -I../common -I../external/include   example_1.o #yes, some redundant flags here

产生的错误消息如下。IDK 如果-lfmt是事情——在SO 页面上看到它

/usr/bin/ld: example_1.o: in function `fmt::v5::internal::count_digits(unsigned long)':
/usr/include/fmt/format.h:908: undefined reference to `fmt::v5::internal::basic_data<void>::ZERO_OR_POWERS_OF_10_64'
/usr/bin/ld: example_1.o: in function `fmt::v5::internal::count_digits(unsigned int)':
/usr/include/fmt/format.h:1011: undefined reference to `fmt::v5::internal::basic_data<void>::ZERO_OR_POWERS_OF_10_32'
/usr/bin/ld: example_1.o: in function `fmt::v5::internal::parse_format_string<false, char, fmt::v5::format_handler<fmt::v5::arg_formatter<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >, char, fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >&>(fmt::v5::basic_string_view<char>, fmt::v5::format_handler<fmt::v5::arg_formatter<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >, char, fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >&)::writer::operator()(char const*, char const*)':
/usr/include/fmt/format.h:2158: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::internal::parse_format_string<false, char, fmt::v5::format_handler<fmt::v5::arg_formatter<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >, char, fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >&>(fmt::v5::basic_string_view<char>, fmt::v5::format_handler<fmt::v5::arg_formatter<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >, char, fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >&)':
/usr/include/fmt/format.h:2175: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: /usr/include/fmt/format.h:2190: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: /usr/include/fmt/format.h:2193: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `fmt::v5::format_handler<fmt::v5::arg_formatter<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >, char, fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::on_format_specs(fmt::v5::internal::null_terminating_iterator<char>)':
/usr/include/fmt/format.h:3330: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o:/usr/include/fmt/format.h:2141: more undefined references to `fmt::v5::internal::error_handler::on_error(char const*)' follow
/usr/bin/ld: example_1.o: in function `void fmt::v5::basic_writer<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::write_double<double>(double, fmt::v5::basic_format_specs<char> const&)':
/usr/include/fmt/format.h:2896: undefined reference to `fmt::v5::internal::grisu2_format(double, char*, unsigned long&, char, int, bool)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::basic_writer<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::write_double<long double>(long double, fmt::v5::basic_format_specs<char> const&)':
/usr/include/fmt/format.h:2896: undefined reference to `fmt::v5::internal::grisu2_format(double, char*, unsigned long&, char, int, bool)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::internal::handle_cstring_type_spec<char, fmt::v5::internal::arg_formatter_base<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::cstring_spec_handler>(char, fmt::v5::internal::arg_formatter_base<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::cstring_spec_handler&&)':
/usr/include/fmt/format.h:1320: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::internal::check_string_type_spec<char, fmt::v5::internal::error_handler>(char, fmt::v5::internal::error_handler&&)':
/usr/include/fmt/format.h:1326: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::internal::check_pointer_type_spec<char, fmt::v5::internal::error_handler>(char, fmt::v5::internal::error_handler&&)':
/usr/include/fmt/format.h:1332: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::basic_writer<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::write_double_sprintf<double>(double, fmt::v5::basic_format_specs<char> const&, fmt::v5::internal::basic_buffer<char>&)':
/usr/include/fmt/format.h:2954: undefined reference to `int fmt::v5::internal::char_traits<char>::format_float<double>(char*, unsigned long, char const*, int, double)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::basic_writer<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::write_double_sprintf<long double>(long double, fmt::v5::basic_format_specs<char> const&, fmt::v5::internal::basic_buffer<char>&)':
/usr/include/fmt/format.h:2954: undefined reference to `int fmt::v5::internal::char_traits<char>::format_float<long double>(char*, unsigned long, char const*, int, long double)'
/usr/bin/ld: example_1.o: in function `fmt::v5::basic_writer<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::int_writer<int, fmt::v5::basic_format_specs<char> >::on_num()':
/usr/include/fmt/format.h:2614: undefined reference to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)'
/usr/bin/ld: example_1.o: in function `fmt::v5::basic_writer<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::int_writer<unsigned int, fmt::v5::basic_format_specs<char> >::on_num()':
/usr/include/fmt/format.h:2614: undefined reference to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)'
/usr/bin/ld: example_1.o: in function `fmt::v5::basic_writer<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::int_writer<long long, fmt::v5::basic_format_specs<char> >::on_num()':
/usr/include/fmt/format.h:2614: undefined reference to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)'
/usr/bin/ld: example_1.o: in function `fmt::v5::basic_writer<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::int_writer<unsigned long long, fmt::v5::basic_format_specs<char> >::on_num()':
/usr/include/fmt/format.h:2614: undefined reference to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)'
/usr/bin/ld: example_1.o: in function `fmt::v5::basic_writer<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::int_writer<char, fmt::v5::basic_format_specs<char> >::on_num()':
/usr/include/fmt/format.h:2614: undefined reference to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::internal::set_dynamic_spec<fmt::v5::internal::width_checker, unsigned int, fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char>, fmt::v5::internal::error_handler>(unsigned int&, fmt::v5::basic_format_arg<fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >, fmt::v5::internal::error_handler)':
/usr/include/fmt/format.h:1794: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::internal::set_dynamic_spec<fmt::v5::internal::precision_checker, int, fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char>, fmt::v5::internal::error_handler>(int&, fmt::v5::basic_format_arg<fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >, fmt::v5::internal::error_handler)':
/usr/include/fmt/format.h:1794: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::internal::handle_char_specs<char, fmt::v5::internal::char_specs_checker<fmt::v5::internal::error_handler, char> >(fmt::v5::basic_format_specs<char> const*, fmt::v5::internal::char_specs_checker<fmt::v5::internal::error_handler, char>&&)':
/usr/include/fmt/format.h:1309: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::internal::handle_cstring_type_spec<char, fmt::v5::internal::cstring_type_checker<fmt::v5::internal::error_handler> >(char, fmt::v5::internal::cstring_type_checker<fmt::v5::internal::error_handler>&&)':
/usr/include/fmt/format.h:1320: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::internal::check_string_type_spec<char, fmt::v5::internal::error_handler&>(char, fmt::v5::internal::error_handler&)':
/usr/include/fmt/format.h:1326: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o:/usr/include/fmt/format.h:1332: more undefined references to `fmt::v5::internal::error_handler::on_error(char const*)' follow
/usr/bin/ld: example_1.o: in function `char* fmt::v5::internal::format_decimal<unsigned int, char, fmt::v5::internal::no_thousands_sep>(char*, unsigned int, unsigned int, fmt::v5::internal::no_thousands_sep)':
/usr/include/fmt/format.h:1064: undefined reference to `fmt::v5::internal::basic_data<void>::DIGITS'
/usr/bin/ld: /usr/include/fmt/format.h:1066: undefined reference to `fmt::v5::internal::basic_data<void>::DIGITS'
/usr/bin/ld: /usr/include/fmt/format.h:1074: undefined reference to `fmt::v5::internal::basic_data<void>::DIGITS'
/usr/bin/ld: /usr/include/fmt/format.h:1076: undefined reference to `fmt::v5::internal::basic_data<void>::DIGITS'
/usr/bin/ld: example_1.o: in function `char* fmt::v5::internal::format_decimal<unsigned long, char, fmt::v5::internal::no_thousands_sep>(char*, unsigned long, unsigned int, fmt::v5::internal::no_thousands_sep)':
/usr/include/fmt/format.h:1064: undefined reference to `fmt::v5::internal::basic_data<void>::DIGITS'
/usr/bin/ld: example_1.o:/usr/include/fmt/format.h:1066: more undefined references to `fmt::v5::internal::basic_data<void>::DIGITS' follow
/usr/bin/ld: example_1.o: in function `fmt::v5::basic_writer<fmt::v5::back_insert_range<fmt::v5::internal::basic_buffer<char> > >::int_writer<unsigned long, fmt::v5::basic_format_specs<char> >::on_num()':
/usr/include/fmt/format.h:2614: undefined reference to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)'
/usr/bin/ld: example_1.o: in function `std::enable_if<fmt::v5::internal::is_integer<int>::value, unsigned long long>::type fmt::v5::internal::width_checker<fmt::v5::internal::error_handler>::operator()<int>(int)':
/usr/include/fmt/format.h:1652: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `std::enable_if<fmt::v5::internal::is_integer<unsigned int>::value, unsigned long long>::type fmt::v5::internal::width_checker<fmt::v5::internal::error_handler>::operator()<unsigned int>(unsigned int)':
/usr/include/fmt/format.h:1652: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `std::enable_if<fmt::v5::internal::is_integer<long long>::value, unsigned long long>::type fmt::v5::internal::width_checker<fmt::v5::internal::error_handler>::operator()<long long>(long long)':
/usr/include/fmt/format.h:1652: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `std::enable_if<fmt::v5::internal::is_integer<unsigned long long>::value, unsigned long long>::type fmt::v5::internal::width_checker<fmt::v5::internal::error_handler>::operator()<unsigned long long>(unsigned long long)':
/usr/include/fmt/format.h:1652: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `std::enable_if<!fmt::v5::internal::is_integer<bool>::value, unsigned long long>::type fmt::v5::internal::width_checker<fmt::v5::internal::error_handler>::operator()<bool>(bool)':
/usr/include/fmt/format.h:1659: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o:/usr/include/fmt/format.h:1659: more undefined references to `fmt::v5::internal::error_handler::on_error(char const*)' follow
/usr/bin/ld: example_1.o: in function `void fmt::v5::basic_writer<fmt::v5::output_range<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::write_double<double>(double, fmt::v5::basic_format_specs<char> const&)':
/usr/include/fmt/format.h:2896: undefined reference to `fmt::v5::internal::grisu2_format(double, char*, unsigned long&, char, int, bool)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::basic_writer<fmt::v5::output_range<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::write_double<long double>(long double, fmt::v5::basic_format_specs<char> const&)':
/usr/include/fmt/format.h:2896: undefined reference to `fmt::v5::internal::grisu2_format(double, char*, unsigned long&, char, int, bool)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::internal::handle_cstring_type_spec<char, fmt::v5::internal::arg_formatter_base<fmt::v5::output_range<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::cstring_spec_handler>(char, fmt::v5::internal::arg_formatter_base<fmt::v5::output_range<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::cstring_spec_handler&&)':
/usr/include/fmt/format.h:1320: undefined reference to `fmt::v5::internal::error_handler::on_error(char const*)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::basic_writer<fmt::v5::output_range<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::write_double_sprintf<double>(double, fmt::v5::basic_format_specs<char> const&, fmt::v5::internal::basic_buffer<char>&)':
/usr/include/fmt/format.h:2954: undefined reference to `int fmt::v5::internal::char_traits<char>::format_float<double>(char*, unsigned long, char const*, int, double)'
/usr/bin/ld: example_1.o: in function `void fmt::v5::basic_writer<fmt::v5::output_range<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::write_double_sprintf<long double>(long double, fmt::v5::basic_format_specs<char> const&, fmt::v5::internal::basic_buffer<char>&)':
/usr/include/fmt/format.h:2954: undefined reference to `int fmt::v5::internal::char_traits<char>::format_float<long double>(char*, unsigned long, char const*, int, long double)'
/usr/bin/ld: example_1.o: in function `char* fmt::v5::internal::format_decimal<unsigned int, char, fmt::v5::internal::add_thousands_sep<char> >(char*, unsigned int, unsigned int, fmt::v5::internal::add_thousands_sep<char>)':
/usr/include/fmt/format.h:1064: undefined reference to `fmt::v5::internal::basic_data<void>::DIGITS'
/usr/bin/ld: /usr/include/fmt/format.h:1066: undefined reference to `fmt::v5::internal::basic_data<void>::DIGITS'
/usr/bin/ld: /usr/include/fmt/format.h:1074: undefined reference to `fmt::v5::internal::basic_data<void>::DIGITS'
/usr/bin/ld: /usr/include/fmt/format.h:1076: undefined reference to `fmt::v5::internal::basic_data<void>::DIGITS'
/usr/bin/ld: example_1.o: in function `char* fmt::v5::internal::format_decimal<unsigned long, char, fmt::v5::internal::add_thousands_sep<char> >(char*, unsigned long, unsigned int, fmt::v5::internal::add_thousands_sep<char>)':
/usr/include/fmt/format.h:1064: undefined reference to `fmt::v5::internal::basic_data<void>::DIGITS'
/usr/bin/ld: example_1.o:/usr/include/fmt/format.h:1066: more undefined references to `fmt::v5::internal::basic_data<void>::DIGITS' follow
/usr/bin/ld: example_1.o: in function `fmt::v5::basic_writer<fmt::v5::output_range<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::int_writer<int, fmt::v5::basic_format_specs<char> >::on_num()':
/usr/include/fmt/format.h:2614: undefined reference to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)'
/usr/bin/ld: example_1.o: in function `fmt::v5::basic_writer<fmt::v5::output_range<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::int_writer<unsigned int, fmt::v5::basic_format_specs<char> >::on_num()':
/usr/include/fmt/format.h:2614: undefined reference to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)'
/usr/bin/ld: example_1.o: in function `fmt::v5::basic_writer<fmt::v5::output_range<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::int_writer<long long, fmt::v5::basic_format_specs<char> >::on_num()':
/usr/include/fmt/format.h:2614: undefined reference to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)'
/usr/bin/ld: example_1.o: in function `fmt::v5::basic_writer<fmt::v5::output_range<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::int_writer<unsigned long long, fmt::v5::basic_format_specs<char> >::on_num()':
/usr/include/fmt/format.h:2614: undefined reference to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)'
/usr/bin/ld: example_1.o: in function `fmt::v5::basic_writer<fmt::v5::output_range<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >::int_writer<char, fmt::v5::basic_format_specs<char> >::on_num()':
/usr/include/fmt/format.h:2614: undefined reference to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)'
/usr/bin/ld: example_1.o:/usr/include/fmt/format.h:2614: more undefined references to `char fmt::v5::internal::thousands_sep<char>(fmt::v5::locale_provider*)' follow
collect2: error: ld returned 1 exit status
make: *** [Makefile:39: example_1.out] Error 1

标签: c++c++20fmt

解决方案


推荐阅读