将yaml-cpp与conan链接

Linking yaml-cpp with conan

本文关键字:链接 conan yaml-cpp      更新时间:2024-09-29

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

其余的库链接正确,所以我的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::char_traits<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<char,std::char_traits,std:;分配器>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