且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

yaml-cpp 的编译器错误 - 未定义对 `YAML::detail::node_data::convert_to_map` 的引用

更新时间:2021-06-29 04:05:52

您似乎没有正确链接 yaml-cpp 库.编译时添加参数-lyaml-cpp.例如:

It seems that you are not properly linking the yaml-cpp library. Add the argument -lyaml-cpp when compiling. For example:

g++ -I/usr/local/include -L/usr/local/lib -lyaml-cpp -o test main.cpp

编辑

另一种选择是将此 cmake 包含到您的 CMakeLists.txt 中:


EDIT

Another option is to include this cmake to your CMakeLists.txt:

# attempt to find static library first if this is set
if(YAMLCPP_STATIC_LIBRARY)
    set(YAMLCPP_STATIC libyaml-cpp.a)
endif()

# find the yaml-cpp include directory
find_path(YAMLCPP_INCLUDE_DIR yaml-cpp/yaml.h
          PATH_SUFFIXES include
          PATHS
          ~/Library/Frameworks/yaml-cpp/include/
          /Library/Frameworks/yaml-cpp/include/
          /usr/local/include/
          /usr/include/
          /sw/yaml-cpp/         # Fink
          /opt/local/yaml-cpp/  # DarwinPorts
          /opt/csw/yaml-cpp/    # Blastwave
          /opt/yaml-cpp/
          ${YAMLCPP_DIR}/include/)

# find the yaml-cpp library
find_library(YAMLCPP_LIBRARY
             NAMES ${YAMLCPP_STATIC} yaml-cpp
             PATH_SUFFIXES lib64 lib
             PATHS ~/Library/Frameworks
                    /Library/Frameworks
                    /usr/local
                    /usr
                    /sw
                    /opt/local
                    /opt/csw
                    /opt
                    ${YAMLCPP_DIR}/lib)

# handle the QUIETLY and REQUIRED arguments and set YAMLCPP_FOUND to TRUE if all listed variables are TRUE
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(YAMLCPP DEFAULT_MSG YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY)
mark_as_advanced(YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY)