编译 C++ Thrift 代码以连接 Cassandra 会导致以下错误。我们在这里缺少啥?

Posted

技术标签:

【中文标题】编译 C++ Thrift 代码以连接 Cassandra 会导致以下错误。我们在这里缺少啥?【英文标题】:Compiling C++ Thrift code to interface Cassandra results in following errors. What are we missing here?编译 C++ Thrift 代码以连接 Cassandra 会导致以下错误。我们在这里缺少什么? 【发布时间】:2012-10-17 13:02:16 【问题描述】: $ g++ -lthrift -Wall thriftfs.cpp cassandra_constants.cpp Cassandra.cpp cassandra_types.cpp -o thriftfs -I/usr/local/include/thrift -L/usr/local/lib 在 /usr/local/include/thrift/protocol/TProtocol.h:23:0 包含的文件中, 来自 /usr/local/include/thrift/TProcessor.h:24, 来自 Cassandra.h:10, 从 t`在此处输入代码`hriftfs.cpp:4: /usr/local/include/thrift/transport/TTransport.h:34:1: 错误:‘uint32_t’没有命名类型 /usr/local/include/thrift/transport/TTransport.h:156:29:错误:ISO C++ 禁止声明没有类型的“buf”[-fpermissive] 在 /usr/local/include/thrift/TProcessor.h:24:0 包含的文件中, 来自 Cassandra.h:10, 来自 thriftfs.cpp:4: /usr/local/include/thrift/protocol/TProtocol.h:184:1: 错误:‘uint32_t’没有命名类型 在 Cassandra.h:10:0 包含的文件中, 来自 thriftfs.cpp:4: /usr/local/include/thrift/TProcessor.h:72:57:错误:“uint32_t”尚未声明 在 cassandra_types.h:11:0 包含的文件中, 来自 Cassandra.h:11, 来自 thriftfs.cpp:4: /usr/local/include/thrift/TApplicationException.h:94:3: 错误:‘uint32_t’没有命名类型 在 Cassandra.h:11:0 包含的文件中, 来自 thriftfs.cpp:4: cassandra_types.h:85:16: 错误:‘uint8_t’没有命名类型 在 Cassandra.h:11:0 包含的文件中, 来自 thriftfs.cpp:4: cassandra_types.h:142:3:错误:“uint32_t”没有命名类型 在 Cassandra.h:11:0 包含的文件中, 来自 thriftfs.cpp:4: cassandra_types.h:1478:16: 错误:‘uint8_t’没有命名类型 在 Cassandra.h:11:0 包含的文件中, 来自 thriftfs.cpp:4: cassandra_types.h:1812:3:错误:“uint32_t”没有命名类型 在 thriftfs.cpp:4:0 包含的文件中: Cassandra.h:217:3:错误:‘uint32_t’没有命名类型 Cassandra.h:4857:35:错误:'org::apache::thrift' 尚未声明 Cassandra.h:4857:62:错误:在“*”标记之前需要“,”或“...” Cassandra.h:4859:71:错误:无法声明指向“void”成员的指针 Cassandra.h:4859:145:错误:模板参数 2 无效 Cassandra.h:4859:145:错误:模板参数 4 无效 Cassandra.h:4860:45:错误:'org::apache::thrift' 尚未声明 Cassandra.h:4860:72:错误:在“*”标记之前需要“,”或“...” Cassandra.h:4935:42:错误:“thrift”不是“org::apache”的成员 Cassandra.h:4935:42:注意:建议的替代方案: /usr/local/include/thrift/Thrift.h:75:37: 注意:‘apache::thrift’ Cassandra.h:4935:42:错误:“thrift”不是“org::apache”的成员 Cassandra.h:4935:42:注意:建议的替代方案: /usr/local/include/thrift/Thrift.h:75:37: 注意:‘apache::thrift’ Cassandra.h:4935:77:错误:模板参数 1 无效 Cassandra.h:4935:105:错误:“thrift”不是“org::apache”的成员 Cassandra.h:4935:105:注意:建议的替代方案: /usr/local/include/thrift/Thrift.h:75:37: 注意:‘apache::thrift’ Cassandra.h:4935:105:错误:“thrift”不是“org::apache”的成员 Cassandra.h:4935:105:注意:建议的替代方案: /usr/local/include/thrift/Thrift.h:75:37: 注意:‘apache::thrift’ Cassandra.h:4935:140:错误:模板参数 1 无效 Cassandra.h:在构造函数“org::apache::cassandra::CassandraProcessor::CassandraProcessor(boost::shared_ptr)”中: Cassandra.h:4898:49: 错误: 分配只读位置 '"login"[((org::apache::cassandra::CassandraProcessor*)this)->org::apache::cassandra::CassandraProcessor: :processMap_]' Cassandra.h:4898:49: 错误: 无法转换'void (org::apache::cassandra::CassandraProcessor::*)(int32_t, int) aka void (org::apach

【问题讨论】:

您找到解决方案了吗? 这个问题好运吗? 看起来像编译器问题 【参考方案1】:

添加以下定义:

g++ -DHAVE_NETINET_IN_H -DHAVE_INTTYPES_H ...

或在您的代码中包含Thrift.h 之前添加#include <stdint.h>

请参阅THRIFT-1326 的讨论。据说该问题已在 thrift 0.9 中修复。

【讨论】:

【参考方案2】:

看来您的问题是编译器问题。

找不到类型“uint32_t”

关于这个还有另一个问题:

'uint32_t' identifier not found error

引自用户templatetypedef

这个类型是在 C 头文件中定义的,目前没有 C++ 标准的一部分。根据***页面 头文件,它直到 VS2010 才随 Visual Studio 一起提供。

与此同时,您可能会伪造自己的版本 通过添加将 Microsoft 的自定义整数类型映射到的 typedef C 期望的类型。例如:

typedef __int32 int32_t; typedef 无符号 __int32 uint32_t; /* ... 等等...... */希望这会有所帮助!

【讨论】:

以上是关于编译 C++ Thrift 代码以连接 Cassandra 会导致以下错误。我们在这里缺少啥?的主要内容,如果未能解决你的问题,请参考以下文章

浅谈Thrift内部实现原理

Thrift 简单实现C#通讯服务程序 (跨语言 MicroServices)

thrift在C++中的应用

Thrift安装介绍

Thrift第七课 服务器多线程发送异常

Apache Thrift C++ GlobalOutput 输出到哪里?