c++cmakeyaml-cpp

Can not link yaml-cpp with my cmake project


My CMakeLists.txt

cmake_minimum_required(VERSION 3.0 FATAL_ERROR) 
project(test_includes)


#find_package(Boost COMPONENTS system filesystem REQUIRED)
#include_directories( ${Boost_INCLUDE_DIRS} )

set(Torch_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libtorch/share/cmake/Torch")

find_package(Boost COMPONENTS system filesystem REQUIRED)
find_package(Threads REQUIRED)
find_package(Torch REQUIRED)
find_package(yaml-cpp REQUIRED)


include_directories( ${Boost_INCLUDE_DIRS}
  ${EIGEN3_INCLUDE_DIR}
  ${yaml-cpp_INCLUDE_DIR}
  ${Torch_INCLUDE_DIRS}
  include)

set(CMAKE_CXX_FLAGS_DEBUG "-g3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g3 -gdwarf -fno-omit-frame-pointer -DNDEBUG")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
add_subdirectory(include)

#link_directories(libraries)

set( LIBS_TO_LINK
                  Domains
                  Agents
                  Planning
                  yaml-cpp
                  ${TORCH_LIBRARIES}
                  ${CMAKE_THREAD_LIBS_INIT})# -llapack)

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

The error message i am getting:

...
[100%] Linking CXX executable testWarehouse
/usr/bin/ld: CMakeFiles/testWarehouse.dir/testWarehouse.cpp.o: in function `WarehouseSimulation(std::string const&, unsigned long)':
testWarehouse.cpp:(.text+0x13af): undefined reference to `YAML::LoadFile(std::string const&)'
/usr/bin/ld: CMakeFiles/testWarehouse.dir/testWarehouse.cpp.o: in function `YAML::detail::node_ref::set_scalar(std::string const&)':
testWarehouse.cpp:(.text._ZN4YAML6detail8node_ref10set_scalarERKSs[_ZN4YAML6detail8node_ref10set_scalarERKSs]+0x2a): undefined reference to `YAML::detail::node_data::set_scalar(std::string const&)'
/usr/bin/ld: CMakeFiles/testWarehouse.dir/testWarehouse.cpp.o: in function `YAML::Node::Scalar() const':
testWarehouse.cpp:(.text._ZNK4YAML4Node6ScalarEv[_ZNK4YAML4Node6ScalarEv]+0x79): undefined reference to `YAML::detail::node_data::empty_scalar()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/testWarehouse.dir/build.make:109: testWarehouse] Error 1
make[1]: *** [CMakeFiles/Makefile2:152: CMakeFiles/testWarehouse.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

note: i do have yamp-cpp installed

my full project: i have tried manually adding -lyaml-cpp to the compile commands, with no effect.

can someone please check my CMakeLists.txt and tell my if am linking yaml-cpp properly, Thanks. (i am 99% sure that it is correct)

i have tried yaml-cpp versions 7.0, 6.3, 5.3 all with the same result

looking at .../build/CMakeCache.txt it includes:

//The directory containing a CMake configuration file for yaml-cpp.
yaml-cpp_DIR:PATH=/usr/share/cmake/yaml-cpp

which looks correct to me

if you need any more info please ask

Thank you


Solution

  • it was pre C++11 ABI issue

    the solution can be found at: https://github.com/pytorch/pytorch/issues/19353#issuecomment-652314883