本文介绍了如何在不获取“体系结构x86_64的未定义符号"的情况下使用仅fmt标头库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用fmt( https://github.com/fmtlib/fmt)格式化我的c ++项目中的标头库.

I'm trying to use the fmt (https://github.com/fmtlib/fmt) formatting header library in my c++ project.

我已将路径添加到主文件顶部的核心头文件中,如下所示:

I've added the path to the core header file at the top of my main file like so:

#include "../third_party/fmt/core.h"

但是当我尝试调用任何函数时:

but when I try to call any function like:

string message = fmt::format("The answer is {}", 42);

我收到以下错误:

Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > fmt::v5::internal::vformat<char>(fmt::v5::basic_string_view<char>, fmt::v5::basic_format_args<fmt::v5::buffer_context<char>::type>)", referenced from:
      std::__1::basic_string<std::__1::enable_if<internal::is_string<char [17]>::value, fmt::v5::internal::char_t<char [17]>::type>::type, std::__1::char_traits<std::__1::enable_if<internal::is_string<char [17]>::value, fmt::v5::internal::char_t<char [17]>::type>::type>, std::__1::allocator<std::__1::enable_if<internal::is_string<char [17]>::value, fmt::v5::internal::char_t<char [17]>::type>::type> > fmt::v5::format<char [17], int>(char const (&) [17], int const&) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [main] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2

我不确定如何使用它,因为这是我过去使用其他标头库(例如cxxopts)的方式.任何帮助将不胜感激!

I'm not sure how to use this as this is how I have used other header libraries in the past such as cxxopts. Any help would be appreciated!

推荐答案

您应链接到fmt库或使用可选的仅标头模式.

例如,如果您有文件test.cc:

#include <fmt/core.h>

int main() {
  fmt::print("The answer is {}.", 42);
}

您可以编译它并将其与gcc链接:

You can compile and link it with gcc:

g++ -std=c++11 test.cc -lfmt

这篇关于如何在不获取“体系结构x86_64的未定义符号"的情况下使用仅fmt标头库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:49