2
我想使用yaml-cpp库来读取一些YAML字符串。为了做到这一点,我尝试编译下面的C++代码:yaml-cpp:链接失败
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <openssl/sha.h>
#include <yaml-cpp/yaml.h>
int main(){
std::string yamlstr = "name: Test\ndescription: Test2";
std::stringstream is(yamlstr);
YAML::Parser parser(is);
YAML::Node doc;
parser.GetNextDocument(doc);
return 0;
}
但是,按预期它不工作,当我运行链接器引发以下错误消息g++ $(pkg-config --cflags --libs yaml-cpp) test.cpp -o test
:
/tmp/ccEPCiDN.o: In function `main':
test.cpp:(.text+0x1e0): undefined reference to `YAML::Parser::Parser(std::basic_istream<char, std::char_traits<char> >&)'
test.cpp:(.text+0x1ef): undefined reference to `YAML::Node::Node()'
test.cpp:(.text+0x209): undefined reference to `YAML::Parser::GetNextDocument(YAML::Node&)'
test.cpp:(.text+0x218): undefined reference to `YAML::Node::~Node()'
test.cpp:(.text+0x227): undefined reference to `YAML::Parser::~Parser()'
test.cpp:(.text+0x403): undefined reference to `YAML::Node::~Node()'
test.cpp:(.text+0x412): undefined reference to `YAML::Parser::~Parser()'
collect2: ld returned 1 exit status
输出的pkg-config --cflags --libs yaml-cpp
:
ls -l /usr/local/lib
的
-I/usr/local/include -L/usr/local/lib -lyaml-cpp
:
[...]
-rw-r--r-- 1 root root 843138 2012-03-01 10:38 libyaml-cpp.a
[...]
我目前使用的是0.3.0版本,但我也检出了当前版本库的副本。
有谁知道如何解决这个问题?
谢谢!/usr/lib中有一个很老的libyaml。我删除它后,一切正常。 – SecStone 2012-03-04 13:26:57