undefined reference to YAML::LoadFile

后端 未结 5 631
梦如初夏
梦如初夏 2020-12-19 17:49

I\'m trying to use the new version of libyaml-cpp and having linker problems (undefined reference to \'YAML::LoadFile(std::basic_string

5条回答
  •  孤城傲影
    2020-12-19 18:38

    I have been struggling over this for the whole evening today. As I found no useful info anywhere in the internet, I post my results here:

    Using OSX El Capitan with new versions of XCode (7.3) and CLang (Apple LLVM version 7.3.0 (clang-703.0.29) Using yaml-cpp 0.5.3

    Things I did to make it work:

    1. Obtain FindYamlCpp.cmake from the internet. Save it in /usr/local/share/cmake/Modules
    2. Set CMakeFiles.txt to find Yaml-cpp

      # YAML with yaml-cpp
      SET(YAMLCPP_STATIC_LIBRARY TRUE)
      FIND_PACKAGE(YamlCpp)
      IF(YamlCpp_FOUND)
          MESSAGE("yaml-cpp Library FOUND: yaml-cpp related sources will be built.")
      ELSEIF(YamlCpp_FOUND)
          MESSAGE("yaml-cpp Library NOT FOUND!")
      ENDIF(YamlCpp_FOUND)
      
    3. Add code to src/CmakeFiles.txt to use FindYamlCpp

          # Enable Yaml 
          IF(YAMLCPP_FOUND)
              ADD_EXECUTABLE(my_exec my_source.cpp)
          ENDIF(YAMLCPP_FOUND)
      
    4. Using for example ccmake:

      1. set CMAKE_MODULE_PATH to /usr/local/share/cmake/Modules
      2. Set CMAKE_EXEC_LINKER_FLAGS to -lyaml-cpp

提交回复
热议问题