首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >yaml-cpp:链接失败

yaml-cpp:链接失败
EN

Stack Overflow用户
提问于 2012-03-01 18:11:35
回答 1查看 3.1K关注 0票数 2

我想使用yaml-cpp库来读取一些YAML字符串。为此,我尝试编译以下C++代码:

代码语言:javascript
复制
#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时,链接器抛出以下错误消息

代码语言:javascript
复制
/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的输出

代码语言:javascript
复制
-I/usr/local/include  -L/usr/local/lib -lyaml-cpp 

ls -l /usr/local/lib的输出

代码语言:javascript
复制
[...]
-rw-r--r-- 1 root root    843138 2012-03-01 10:38 libyaml-cpp.a
[...]

我目前使用的是0.3.0版本,但我也签出了当前存储库的一个副本。

有人知道如何解决这个问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-02 02:06:32

有几种可能性:

  1. 是否有可能yaml-cpp的共享库版本的旧版本在您的库路径中?
  2. 如果您尝试首先在命令行中使用test.cpp进行编译,会发生什么,例如,

配置$(pkg- test.cpp --cflags -libs yaml-cpp) -o

(顺便说一句,对于更强大的googling搜索能力,这是一个静态链接问题,而不是编译问题。)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9514284

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档