我正在尝试创建一个将两个数字相乘的简单节俭服务器。
我已经像这样编写了节俭文件:
namespace cpp tutorial
typedef i32 int
service MultiplicationService
{
int multiply(1:int n1, 2:int n2),
}
之后我跑了thrift --gen cpp multi.thrift
我将骨架文件重命名为MultiplicationServer.cpp
:
#include "MultiplicationService.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
using boost::shared_ptr;
using namespace ::tutorial;
class MultiplicationServiceHandler : virtual public MultiplicationServiceIf {
public:
MultiplicationServiceHandler() {
// Your initialization goes here
}
int multiply(const int n1, const int n2) {
return n1 * n2;
}
};
int main(int argc, char **argv) {
int port = 9090;
shared_ptr<MultiplicationServiceHandler> handler(new MultiplicationServiceHandler());
shared_ptr<TProcessor> processor(new MultiplicationServiceProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();
return 0;
}
但是当我尝试构建它时,我在 multi_types.h 文件中收到此错误:multiple types in one declaration
在 typedef int32_t int 行上 multi_types.h 文件如下所示:
/**
* Autogenerated by Thrift Compiler (0.9.2)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
#ifndef multi_TYPES_H
#define multi_TYPES_H
#include <iosfwd>
#include <thrift/Thrift.h>
#include <thrift/TApplicationException.h>
#include <thrift/protocol/TProtocol.h>
#include <thrift/transport/TTransport.h>
#include <thrift/cxxfunctional.h>
namespace tutorial {
typedef int32_t int;
} // namespace
#endif
我尝试删除该行,但随后出现很多undefined reference to
错误。
我究竟做错了什么?