Search code examples
c++cmakelinkergit-submodulesyaml-cpp

CMake - Linker error with static yaml-cpp as git submodule


I am trying to use yaml-cpp in my project. I am using cmake to build both my project and yaml-cpp which is a git submodule in my project.

I have the boost library on my computer (required by yaml-cpp).

I am building it statically. Using add_subdirectory in my main CMakeLists.txt then using target_link_libraries(components yaml-cpp) (component is a static library I am using on different modules of my project).

I have an error during the linking phase for one of my source files :

CMakeFiles/rsa-packer.dir/options/addObject.cpp.o : In function « YAML::detail::node& YAML::detail::node_data::get<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::shared_ptr<YAML::detail::memory_holder>) » :
~/git/apps/rsa-packer/options/addObject.cpp:(.text._ZN4YAML6detail9node_data3getINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEERNS0_4nodeERKT_N5boost10shared_ptrINS0_13memory_holderEEE[_ZN4YAML6detail9node_data3getINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEERNS0_4nodeERKT_N5boost10shared_ptrINS0_13memory_holderEEE]+0x157) : undefined reference to: « YAML::detail::node_data::convert_to_map(boost::shared_ptr<YAML::detail::memory_holder>) »

I checked the make output, there is the -lyaml-cpp option. I checked the libyaml-cpp.a file, it contains the function (but I do not really understand the output of nm :

000000000000005d r .L__PRETTY_FUNCTION__._ZN4YAML6detail9node_data14convert_to_mapESt10shared_ptrINS0_13memory_holderEE
0000000000000940 T _ZN4YAML6detail9node_data14convert_to_mapESt10shared_ptrINS0_13memory_holderEE

The weird thing is :

// this works
YAML::Node node = YAML::Load(manifest.getStream());

// this does not work
if(node["objects"]) {
    std::cout << "no objects" << std::endl;
}

I can build the node object using the YAML::Load function that works and is found in the static lib.

But I can't call node["..."] because the function is not found in the lib.

I have no idea what is causing this error.

I don't know if it can lead to problems, but I am compiling my project in C++14 and the yaml-cpp lib is built using c++11.

Thanks!


Solution

  • Ok, I was tired...

    mongodb had already installed yaml-cpp on my computer. I was using the headers files from mongodb with the static library I just compiled from sources... The header was calling the function with boost::shared_ptr and my library was implemented using std::shared_ptr