【发布时间】:2023-03-05 09:39:01
【问题描述】:
这是完整的日志:
/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
我要编译的代码很简单
#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;
}
我使用的 YAML 是来自 http://www.yaml.org/start.html 的示例
如果我只是尝试加载 YAML,它可以正常加载。但是,如果我尝试访问任何数据,我会得到同样的错误。所以这不是链接问题。
编辑:我可以执行 cout << test 和 cout << test.type() 之类的操作以及其他功能。我认为问题在于使用基于字符串的映射来访问内部节点。
【问题讨论】:
-
这不是完整的日志,这只是错误消息。您有一个链接错误,因此您需要向我们展示失败的链接命令。错误来自于
g++ ...命令。将其发布在您的问题正文中。 -
@Mike Kinghan`在函数
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 toYAML::detail::node_data::convert_to_map(boost::shared_ptr<:detail::memory_holder>)'` -
@MikeKinghan 不幸的是我无法编辑帖子,因为它不是我的帖子,但我的 cmake 文件位于本页末尾的 cmets 中......
标签: c++ yaml undefined-reference yaml-cpp