将 yaml-cpp 与 conan 联系起来

问题描述

我在我的柯南文件 yaml-cpp 中使用来自 conan centeryaml-cpp/0.6.3 以及其他依赖项。

其余的库链接正确,因此我的 CMakeLists.txt 文件中肯定缺少某些内容。 (也许是一些额外的定义......?)

直到现在,这些行:

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
set(CMAKE_CXX_STANDARD 20)

它工作得很好(对于其他库,如bullet、glm...)

链接时,会出现缺少实现的问题:

cmake --build build --config Debug --target all -- -j 10
/usr/bin/ld: CMakeFiles/my-project.dir/src/MySourceFile.cpp.o: in function `YAML::Node::Scalar[abi:cxx11]() const':
/home/my-user/.conan/data/yaml-cpp/0.6.3/_/_/package/82ef5eac51c38971dea2fd342dd55ddf2ddfbbc3/include/yaml-cpp/node/impl.h:169: undefined reference to `YAML::detail::node_data::empty_scalar[abi:cxx11]()'
/usr/bin/ld: CMakeFiles/my-project.dir/src/MySource.cpp.o: in function `tojson::loadyaml(std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char> > const&)':
/home/my-user/my-project/lib/nlohmann/tojson.hpp:162: undefined reference to `YAML::LoadFile(std::__cxx11::basic_string<char,std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status

似乎问题在于 YAML::LoadFile 似乎未定义。

(我也尝试在没有 tojson 的情况下使用它)

YAML::Node test = YAML::LoadFile("test.yaml");

解决方法

包没问题,但您的配置文件配置错误。

对`YAML::LoadFile(std::__cxx11::basic_string const&)' 的未定义引用 collect2:错误:ld 返回 1 个退出状态

您必须更新您的 libcxx 设置:

conan profile update settings.compiler.libcxx=libstdc++11 default

更多信息:https://docs.conan.io/en/latest/howtos/manage_gcc_abi.html