Can not link `yaml-cpp` with `libtorch`

$ cmake --version                           
cmake version 3.24.2


cmake_minimum_required(VERSION 3.0 FATAL_ERROR) 

set(Torch_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libtorch/share/cmake/Torch")
find_package(yaml-cpp REQUIRED)
find_package(Torch REQUIRED)



add_executable(testWarehouse testWarehouse.cpp )
target_link_libraries( testWarehouse ${LIBS_TO_LINK} )

main file (testWarehouse.cpp in my case)

#include <yaml-cpp/yaml.h>
//#include <torch/torch.h>

int main(int argc, char* argv[]){
	YAML::Node test_node = YAML::LoadFile("test");


cmake .. && make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/master-andreas/temp/build
Consolidate compiler generated dependencies of target testWarehouse
[ 50%] Building CXX object CMakeFiles/testWarehouse.dir/testWarehouse.cpp.o
[100%] Linking CXX executable testWarehouse
/usr/bin/ld: CMakeFiles/testWarehouse.dir/testWarehouse.cpp.o: in function `main':
testWarehouse.cpp:(.text+0x54): undefined reference to `YAML::LoadFile(std::string const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/testWarehouse.dir/build.make:102: testWarehouse] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/testWarehouse.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Note: if you want to replicate, you will have to install libtorch


I have tried libtorch versions 10.1, 10.2, 11.0,12.0,12.1 and yaml-cpp versions 6.3, 7.0
all with the same results

Are you sure it’s yaml-cpp and not YAML_CPP_LIBRARIES?
This is the docu comment from yaml-cpp config:

# - Config file for the yaml-cpp package
# It defines the following variables
#  YAML_CPP_INCLUDE_DIR       - include directory
#  YAML_CPP_LIBRARY_DIR       - directory containing libraries
#  YAML_CPP_SHARED_LIBS_BUILT - whether we have built shared libraries or not
#  YAML_CPP_LIBRARIES         - libraries to link against

This still fails

Well, you probably have to check what’s in those variables. Maybe those are only library names and one have to add YAML_CPP_LIBRARY_DIR to the link directories?


This looks right to me


This appears to be empty, could it be an issue

To clarify (because with @fenrir, the topic went a bitt off-topic), It can link just yaml-cpp it can link just libtorch, but when trying to link both it fails

OK, I decided to google. In 2 Minutes I hit this: Linking torch libraries and yaml-cpp gives undefined reference to yaml-cpp libraries · Issue #19353 · pytorch/pytorch · GitHub
so this is an ABI incompatibility. There’s a solution / workaround in second-to-last comment as I’m writing this.

TL;DR: Use wget