c++ - Apache Thrift 在生成的代码中未定义对 vtable 的引用
问题描述
我在一个项目中使用 Apache Thrift。我为客户端生成了代码。当我尝试编译时,我得到一组类似的链接器错误:
undefined reference to `vtable for com::cybersecwise::thrift::ElasticFSServiceClient'
我在尝试使用点范围解析来实现构造函数时遇到了同样的错误,但我能够通过在 hpp 文件中实现它来摆脱它。也就是下面的代码:
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);
}
现在的问题是我正在实例化该类,并再次获得对 vtable 的未定义引用。
我知道当没有为虚函数定义声明时,此错误是相关联的。问题是只要我不实例化对象,它似乎编译得很好。
ElasticFSThriftClient elasticFsClient("localhost", 9090);
解决方案
其实很简单。我在编译项目时忘记添加生成的代码文件。
推荐阅读
- swift - 为什么在所有边缘上固定 UIStackView 会导致模棱两可的约束错误?
- javascript - 等待循环完成,然后从中获取数据
- asp.net-mvc - 在其他项目的 mvc 中使用 partials
- google-apps-script - 返回箭头和烤肉串菜单未显示在 gmail 插件的 Gmail 应用程序中
- database - 拆分大型数据库的问题
- .net-core - 无法连接到 .NET core 3.1 中的远程 SignalR 集线器
- .net-core - 无法停止使用 BackgroundService 的 Windows 服务
- common-lisp - 如何在 cl-dbi 中插入 NULL 值
- android - 脱机时不显示 React-Native Webview html 文件
- html - 如何给一个空的 HTML div CSS 样式(背景)?