简体   繁体   English

Apache Thrift 在生成的代码中未定义对 vtable 的引用

[英]Apache Thrift undefined reference to vtable in Generated Code

I'm using Apache Thrift in a project.我在一个项目中使用 Apache Thrift。 I generated code for the client.我为客户端生成了代码。 When I attempt to compile I get a set of similar linker errors:当我尝试编译时,我收到一组类似的链接器错误:

undefined reference to `vtable for com::cybersecwise::thrift::ElasticFSServiceClient'

I got this same error when trying to implement the constructor using point scope resolution, but I was able to get rid of it by implementing it in the hpp file.我在尝试使用点范围解析实现构造函数时遇到了同样的错误,但我能够通过在 hpp 文件中实现它来摆脱它。 That is, the following code:也就是说,下面的代码:

ElasticFSThriftClient(const string& server, int port) {
  stdcxx::shared_ptr<TTransport> socket(new TSocket(server, port));
  stdcxx::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
  stdcxx::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
  ElasticFSServiceClient client(protocol);
}

The problem now is I'm instantiating the class, and getting the undefined reference to vtable again.现在的问题是我正在实例化该类,并再次获取对 vtable 的未定义引用。

I am aware that this error is associated when declarations are not defined for virtual functions.我知道当没有为虚函数定义声明时,会出现此错误。 The thing is it seems to compile just fine as long as I don't instantiate the object.问题是它似乎编译得很好,只要我不实例化对象。

ElasticFSThriftClient elasticFsClient("localhost", 9090);

It was actually quite simple.其实很简单。 I forgot to add the generated code files when compiling the project.编译项目时忘记添加生成的代码文件了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM