错误:未定义模板 'llvm::yaml::MissingTrait 的隐式实例化 [英] error: implicit instantiation of undefined template 'llvm::yaml::MissingTrait

查看:49
本文介绍了错误:未定义模板 'llvm::yaml::MissingTrait 的隐式实例化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 LLVM YAML I/O 库的项目.这是我正在关注的文档/教程:

I am working on a project which uses the LLVM YAML I/O library. This is the documentation/tutorial that I am following:

我正在尝试复制您在 llvm::yaml::MappingTraits 上为 struct 数据类型定义专门化的示例.此示例位于页面顶部.

I am trying to replicate the example where you define a specialization on llvm::yaml::MappingTraits for a struct data type. This example is at the top of the page.

这是我写的代码:

#include <cstdlib>  /* for EXIT_FAILURE */
#include <string>
#include <vector>

#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/YAMLParser.h"

using std::string;
using std::vector;

using llvm::outs;
using llvm::errs;

using llvm::yaml::ScalarEnumerationTraits;
using llvm::yaml::MappingTraits;
using llvm::yaml::IO;
using llvm::yaml::Input;
using llvm::yaml::Output;

struct Person {
    string name;
    int hatSize;
};

template <>
struct MappingTraits<Person> {
    static void mapping(IO& io, Person& info) {
        io.mapRequired("name", info.name);
        io.mapOptional("hat-size", info.hatSize);
    }
};

int main(int argc, const char **argv) {
    Person tom;
    tom.name = "Tom";
    tom.hatSize = 8;
    Person dan;
    dan.name = "Dan";
    dan.hatSize = 7;
    std::vector<Person> persons;
    persons.push_back(tom);
    persons.push_back(dan);

    Output yout(llvm::outs());
    yout << persons;

    return EXIT_SUCCESS;
}

在我看来,我已经完全复制了他们在该教程中的示例代码.但是当我尝试编译程序(使用 makefile)时,我收到了这个神秘的错误消息:

It seems to me that I have replicated the example code that they have in that tutorial exactly. But when I try to compile the program (using makefile) I get this cryptic error message:

clang++ -I/usr/local/include -std=c++11   -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -std=c++14 -fcxx-exceptions -g -Wall   -c -o yaml_project.o yaml_project.cpp
In file included from yaml_project.cpp:12:
/usr/local/include/llvm/Support/YAMLTraits.h:1871:36: error: implicit instantiation of undefined template 'llvm::yaml::MissingTrait<std::vector<Person, std::allocator<Person> > >'
  char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
                                   ^
yaml_project.cpp:153:10: note: in instantiation of function template specialization 'llvm::yaml::operator<<<std::vector<Person, std::allocator<Person> > >' requested here
    yout << persons;
         ^
/usr/local/include/llvm/Support/YAMLTraits.h:307:8: note: template is declared here
struct MissingTrait;
       ^
1 error generated.
<builtin>: recipe for target 'yaml_project.o' failed
make: *** [yaml_project.o] Error 1

我不认为错误出在我用来编译这个程序的命令中,因为它在编译 LLVM 库并将其链接到我的可执行文件之前对我有用.我认为问题出在代码上,但我无法确定是什么.

I don't think that the error is in the command that I am using to compile this program, because it has worked for me before to compile and link the LLVM libraries into my executable. I think that the problem is in the code, but I cannot identify what.

上述头文件llvm/Support/YAMLTraits.h的代码在这里:

The code for the mentioned header file llvm/Support/YAMLTraits.h is here:

https://llvm.org/doxygen/YAMLTraits_8h_source.html

推荐答案

阅读文档,在我看来,对特定vector 的支持需要注册一个宏:

Reading the documentation, it seems to me that support for your specific vector<Person> requires registration with a macro:

LLVM_YAML_IS_SEQUENCE_VECTOR(Person)
// or
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(Person)

参见实用宏:https://llvm.org/docs/YamlIO.html#id22

这篇关于错误:未定义模板 'llvm::yaml::MissingTrait 的隐式实例化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆