我想使用yaml-cpp库来读取一些YAML字符串。为此,我尝试编译以下C++代码:
#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 statuspkg-config --cflags --libs yaml-cpp的输出
-I/usr/local/include -L/usr/local/lib -lyaml-cpp ls -l /usr/local/lib的输出
[...]
-rw-r--r-- 1 root root 843138 2012-03-01 10:38 libyaml-cpp.a
[...]我目前使用的是0.3.0版本,但我也签出了当前存储库的一个副本。
有人知道如何解决这个问题吗?
发布于 2012-03-02 02:06:32
有几种可能性:
test.cpp进行编译,会发生什么,例如,配置$(pkg- test.cpp --cflags -libs yaml-cpp) -o
(顺便说一句,对于更强大的googling搜索能力,这是一个静态链接问题,而不是编译问题。)
https://stackoverflow.com/questions/9514284
复制相似问题