$ cmake --version
cmake version 3.24.2
CMakeList.txt
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(test_project)
set(Torch_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libtorch/share/cmake/Torch")
find_package(yaml-cpp REQUIRED)
find_package(Torch REQUIRED)
include_directories(
${yaml-cpp_INCLUDE_DIR}
${Torch_INCLUDE_DIRS}
)
set( LIBS_TO_LINK
${TORCH_LIBRARIES}
yaml-cpp
)
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");
}
output
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
wget https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-1.10.1%2Bcpu.zip
unzip libtorch-shared-with-deps-1.10.1+cpu.zip
rm libtorch-shared-with-deps-1.10.1+cpu.zip
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