jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
4.91k stars 1.78k forks source link

Unable to build any application that uses yaml-cpp, linker errors #1219

Open divyansh2681 opened 10 months ago

divyansh2681 commented 10 months ago

I am building an application that uses yaml-cpp but I get these errors:

/usr/bin/ld: CMakeFiles/transcribe.dir/transcribe.cpp.o: in function `returnVocabulary(std::string const&)':
transcribe.cpp:(.text+0x55786): undefined reference to `YAML::LoadFile(std::string const&)'
/usr/bin/ld: CMakeFiles/transcribe.dir/transcribe.cpp.o: in function `YAML::detail::node_ref::set_scalar(std::string const&)':
transcribe.cpp:(.text._ZN4YAML6detail8node_ref10set_scalarERKSs[_ZN4YAML6detail8node_ref10set_scalarERKSs]+0x2e): undefined reference to `YAML::detail::node_data::set_scalar(std::string const&)'
/usr/bin/ld: CMakeFiles/transcribe.dir/transcribe.cpp.o: in function `YAML::Node::Scalar() const':
transcribe.cpp:(.text._ZNK4YAML4Node6ScalarEv[_ZNK4YAML4Node6ScalarEv]+0x7d): undefined reference to `YAML::detail::node_data::empty_scalar()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/transcribe.dir/build.make:113: transcribe] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/transcribe.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

My CMakeLists.txt is as follows:

cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
project(transcribe)

include_directories(
    ${CMAKE_SOURCE_DIR}
    /home/divyansh/Documents/onnxruntime-linux-x64-gpu-1.15.1/include
    ${CMAKE_SOURCE_DIR}/yaml-cpp/include/yaml-cpp
)
link_directories(/home/divyansh/Documents/onnxruntime-linux-x64-gpu-1.15.1/lib
                ${CMAKE_SOURCE_DIR}/yaml-cpp/build
                )
set(Torch_DIR /home/divyansh/.local/lib/python3.10/site-packages/torch/share/cmake/Torch)
find_package(Torch REQUIRED)
find_package(yaml-cpp REQUIRED)
link_libraries(${CMAKE_SOURCE_DIR}/yaml-cpp/build/libyaml-cpp.a)
add_executable(transcribe transcribe.cpp)
target_link_libraries(transcribe PRIVATE "${TORCH_LIBRARIES}" onnxruntime yaml-cpp)
set_property(TARGET transcribe PROPERTY CXX_STANDARD 17)
sumedhfb commented 4 months ago

Facing the same issue, did you get a chance to find a work around/solution?

divyansh2681 commented 4 months ago

In my case, the YAML file was very straight forward, so I parsed it as a text file and wrote a function to extract the data that I need from the file.

AlessandroZavoli commented 3 months ago

Can you try a different version? maybe the 0.7.0 ?