Compiler error with yaml-cpp - undefined reference to `YAML::detail::node_data::convert_to_map`

undefined reference to yaml::detail::node_data::empty_scalar(abi:cxx11)
yaml-cpp node to string
yaml-cpp check if key exists
c++ write yaml
yaml-cpp cmake
yaml-cpp bool
yaml node types
yaml parser github

Here's the complete log:

/tmp/ccCvErNZ.o: In function `YAML::detail::node& YAML::detail::node_data::get<std::string>(std::string const&, std::shared_ptr<YAML::detail::memory_holder>)':
cricket.cpp:(.text._ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_St10shared_ptrINS0_13memory_holderEE[_ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_St10shared_ptrINS0_13memory_holderEE]+0x94): undefined reference to `YAML::detail::node_data::convert_to_map(std::shared_ptr<YAML::detail::memory_holder>)'
collect2: error: ld returned 1 exit status

The code I'm trying to compile is simple

#include <iostream>
#include <yaml-cpp/yaml.h>

using namespace std;

int main() {
    YAML::Node test = YAML::LoadFile("test.yaml");
    if (test["date"]) {
      cout << "HELLO";
    }

    return 0;
}

The YAML I'm using is the example from http://www.yaml.org/start.html

If I just try to load the YAML, it loads fine. But if I try to access any data I get the same error. So it's not a linking problem.

EDIT: I can do things like cout << test and cout << test.type() and other functions. I think the problem is in using a string based map for accessing internal nodes.

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

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)

Fails to compile. Undefined reference to YAML::LoadFile · Issue , I don't think there are any other versions of yaml-cpp floating around, and I still errors appear like "Undefined reference to YAML::LoadFile". undefined reference to `YAML I have not installed any other yaml-cpp content of toolchain.cmake to build the library using the cross compiler: SET(CMAKE

I experienced something similar to this when trying to compile OpenXcom on a Debian system. It turned out that I was using a mix of testing and stable packages, the yaml package was from stable, and the combination somehow made linking fail if there were more than just a few initial functions.

If that is what you're experiencing (and you're using Debian too), try compiling a source package from stable with

apt-get --build source libyaml-cpp0.5/stable

This command will build .deb packages for libyaml, and you can then insert them with dpkg like this:

dpkg -i libyaml-cpp0.5*.deb

as root.

Compiling libyaml from source will make it link to the testing libraries you already have, instead of expecting stable libraries, and so should solve the problem above. It did for me, at least.

Even if you don't use Debian, compiling yaml-cpp from source (e.g. a tarball) might work for similar reasons.

Undefined symbols: YAML::Node::~Node() · Issue #554 , This is my main.cpp: #include "yaml-cpp/node/node.h" #include error: '​shared_ptr' in namespace 'std' does not name a template type typedef std::​shared_ptr<node_data> error: 'shared_memory_holder' in namespace 'YAML::​detail' does not name a type undefined reference to YAML::LoadFile #564. I'm trying to get a simple test program to run that looks like this: // main.cpp #include <iostream> #include "yaml-cpp/yaml.h" int main(int argc, const char *argv

Make sure these two files exist:

/usr/local/lib/libyaml-cpp.a
/usr/local/include/yaml-cpp/yaml.h

My CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 3.4)
FIND_PACKAGE(yaml-cpp REQUIRED)
ADD_EXECUTABLE(yaml_cpp_test yaml_cpp_test.cpp)
TARGET_LINK_LIBRARIES(yaml_cpp_test yaml-cpp)

The content of yaml_cpp_test.cpp is same as mentioned in the question.


I try to reappear the problem on vps (Ubuntu 14.04.1 LTS)

wget -c https://github.com/jbeder/yaml-cpp/archive/release-0.5.1.tar.gz
tar xvf release-0.5.1.tar.gz yaml-cpp-release-0.5.1/
cd yaml-cpp-release-0.5.1/
sudo apt-get install cmake
sudo apt-get install libboost-dev
cmake .
make
make install

after that, yaml-cpp install to /usr/local/lib and /usr/local/include files in my working directory:

fqlgy@li407-86:~/yaml-cpp$ ll
total 12
-rw-r--r-- 1 fqlgy fqlgy 162 May  8 03:29 CMakeLists.txt
-rw-r--r-- 1 fqlgy fqlgy  10 May  8 03:11 test.yaml
-rw-r--r-- 1 fqlgy fqlgy 240 May  8 03:11 yaml_cpp_test.cpp

As i tried to run "cmake .", there is some error, so i delete the line CMakeFiles/CMakeOutput.log, the content of CMakeLists.txt is :

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
ADD_EXECUTABLE(yaml_cpp_test yaml_cpp_test.cpp)
TARGET_LINK_LIBRARIES(yaml_cpp_test yaml-cpp)

The following output is as expected:

fqlgy@li407-86:~/yaml-cpp$ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fqlgy/yaml-cpp
fqlgy@li407-86:~/yaml-cpp$ make
Scanning dependencies of target yaml_cpp_test
[100%] Building CXX object CMakeFiles/yaml_cpp_test.dir/yaml_cpp_test.cpp.o
Linking CXX executable yaml_cpp_test
[100%] Built target yaml_cpp_test
fqlgy@li407-86:~/yaml-cpp$ ./yaml_cpp_test
HELLO

jbeder/yaml-cpp, I trying to use yaml-cpp for parsing simple yaml file. OS: macOS Siera 10.12.2 undefined reference to `YAML::Parser::~Parser() #481. Closed. I want to use yaml-cpp library to parse some configuration file, but when I link yaml-cpp and libtorch together, I got undefined reference to YAML::LoadFile(). File main.cpp: #include &quot;yaml-cp

I confirm that certain versions of yaml-cpp library contain this issue (and it is not about improper linking). It is rather dirty, but I've resolved it by defining empty functions in my code, it looks like

    YAML::BadConversion::~BadConversion()
    {
    }

    void  YAML::detail::node_data::convert_to_map(std::shared_ptr<YAML::detail::memory_holder>)
    {
    }

The approach is not perfect (e.g. because it causes duplicates if another library version is used).

c++ - undefined reference yaml-cpp, undefined reference to `YAML::detail::node_data::convert_to_map(std::​shared_ptr<YAML::detail::memory_holder>)' collect2: error: ld returned 1 exit status  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Undefined reference to `vtable for YAML::BadConversion' error , Compiler error with yaml-cpp - undefined reference to `YAML::detail::node_data::​convert_to_map`. Here's the complete log: /tmp/ccCvErNZ.o: In function  @z00m1n: @md5i is right; you should be including "yaml-cpp/yaml.h".The includes "yaml-cpp/node/node.h" and friends are private headers.. And if you're curious about whether the project builds, you can check the Travis link; it has continuous tests run for both Mac OS and Linux.

Debug/loader.cpp.o: in function « YAML::detail::node_ref::set_null() undefined reference to « YAML::detail::node_data::mark_defined()  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more undefined reference with YAML::node::Scalar

Undefined reference to `vtable for YAML::BadConversion' error solution. tags: yaml. Bug. When compiling to the yaml program, I encountered the following error: undefined reference to `YAML::detail::node_data::convert_to_map(std::​shared_ptr< Download version 5.7 of yamlhttps://github.com/jbeder/yaml-cpp/​releases,  Hi, I'm compiling yaml-cpp from source with MSVC 2015, in the RelWithDebInfo x64 configuration, with BUILD_SHARED_LIBS=ON specified. The code fails to link due to lack of YAML_CPP_API on classes in exceptions.h: 6>load_node_test.obj : er

Comments
  • That's not the complete log, that's just the error messages. You have a linkage error so you need to show us the failing linkage command. It is the g++ ... command from which the errors follow. Post it in the body of your question.
  • @Mike Kinghan ` In function YAML::detail::node& YAML::detail::node_data::get<std::string>(std::string const&, boost::shared_ptr<YAML::detail::memory_holder>)': /usr/include/yaml-cpp/node/detail/impl.h:89: undefined reference to YAML::detail::node_data::convert_to_map(boost::shared_ptr<YAML::detail::memory_holder>)'`
  • @MikeKinghan unfortunately I cannot edit the post, since it is not my post, but my cmake file is in the comments at the end of this page....
  • here is my cmake: find_package(yaml-cpp REQUIRED) set(PCL_BUILD_TYPE Release) add_executable (extract_c src/main.cpp) target_link_libraries (extract_c yaml-cpp)
  • Take a loot at this cmake to find yaml-cpp github.com/supercollider/supercollider/blob/master/…
  • what do you mean by then insert it with dpkg
  • Use dpkg -i to install the packages the compilation process creates. I've elaborated on how to do so now.
  • Do I need to do dpkg remove to the current yaml-cpp?
  • If your current yaml-cpp is already 0.5, it shouldn't matter because it should just replace the old one with the new one. However, I'm not entirely certain, so remove the current one just to be sure if it's not too much of a hassle.
  • I did all of the above and till getting the same linking error!
  • I did the exact same thing and still, I got the same error...this is crazy!
  • In function YAML::detail::node& YAML::detail::node_data::get<std::string>(std::string const&, boost::shared_ptr<YAML::detail::memory_holder>)': yaml_example.cpp:(.text._ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_N5boost10shared_ptrINS0_13memory_holderEEE[_ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_N5boost10shared_ptrINS0_13memory_holderEEE]+0xae): undefined reference to YAML::detail::node_data::convert_to_map(boost::shared_ptr<YAML::detail::memory_holder>)'
  • may you try to run "nm /usr/local/lib/libyaml-cpp.a |grep convert_to_map" to check the symbol?
  • 0000000000001670 T _ZN4YAML6detail9node_data14convert_to_mapEN5boost10shared_ptrINS0_13memory_holderEEE 0000000000000060 r _ZZN4YAML6detail9node_data14convert_to_mapEN5boost10shared_ptrINS0_13memory_holderEEEE19__PRETTY_FUNCTION__
  • It' ok to build from source. I will try it on the same os version and give you feedback later.