为什么我无法链接到用 conan 安装的 spdlog 库

sam*_*ode 1 c++ spdlog conan

我有一个简单的 CMake 项目,并尝试使用 conan 安装的 spdlog 库(版本 1.5.0)。

但是在构建时出现以下错误:

undefined reference to `spdlog::get(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
Run Code Online (Sandbox Code Playgroud)

我不确定问题是否来自我的设置、conan 或 spdlog 库。谁能帮我去哪里看?

我的本地设置:Ubuntu 19.04、QT Creator、Clang 9(在 IDE 和 conan 中)、conan 1.24.0

dro*_*dri 7

请首先从 Conan 文档https://docs.conan.io/en/latest/getting_started.html中的“入门”开始,确保它有效,然后从那里开始做你自己的示例。

在入门中,您将看到一个使用 ConanCenter 中现有库的示例。还有一个显着的“重要”通知,上面写着:

If you are using GCC compiler >= 5.1, Conan will set the compiler.libcxx to the old ABI for backwards compatibility. You can change this with the following commands:

$ conan profile new default --detect  # Generates default profile detecting GCC and sets old ABI
$ conan profile update settings.compiler.libcxx=libstdc++11 default  # Sets libcxx to C++11 ABI
Run Code Online (Sandbox Code Playgroud)

基本上,默认的自动检测配置文件使用 libstdc++,而您的编译器很可能使用 libstdc++11。您需要使用以下命令更改默认配置文件:

$ conan profile update settings.compiler.libcxx=libstdc++11 default
Run Code Online (Sandbox Code Playgroud)

然后再次执行“conan install”并构建。