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:EDIT
Another option is to include this cmake to your CMakeLists.txt:
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
This command will build .deb packages for libyaml, and you can then insert them with dpkg like this:
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.
Make sure these two files exist:
My CMakeLists.txt:
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)
after that, yaml-cpp install to /usr/local/lib and /usr/local/include
files in my working directory:
As i tried to run "cmake .", there is some error, so i delete the line
CMakeFiles/CMakeOutput.log
, the content of CMakeLists.txt is :The following output is as expected: