Search code examples
c++cmakeconanyaml-cpp

Linking yaml-cpp with conan


I'm using yaml-cpp from conan center, in my conan file, yaml-cpp/0.6.3, along with other dependencies.

The rest of the libraries link properly, so there must be something missing in my CMakeLists.txt file. (Maybe some extra definition...?)

Until now, with those lines:

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

It worked fine (For other libraries, like bullet, glm...)

At link time, problems with missing implementation arise:

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

Seems that the problem is that YAML::LoadFile appears to be undefined.

(I've tried using it without tojson also)

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

Solution

  • The package is okay, but your profile is misconfigured.

    undefined reference to `YAML::LoadFile(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' collect2: error: ld returned 1 exit status

    You have to update your libcxx setting:

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

    More info about: https://docs.conan.io/en/latest/howtos/manage_gcc_abi.html