2014-11-30 8 views
0

두 개의 숫자를 곱하는 간단한 중고품 서버를 만들려고합니다.Apache Thrift C++ typedef 문제

이 같은 중고품 파일을 작성했습니다

:

#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; 
} 
: 그 내가 다음과 같습니다 MultiplicationServer.cpp에 골격 파일의 이름을 변경

thrift --gen cpp multi.thrift를 실행 한 후

namespace cpp tutorial 

typedef i32 int 

service MultiplicationService 
{ 

    int multiply(1:int n1, 2:int n2), 

} 

하지만 그것을 빌드하려고하면 multi_types.h 파일에이 오류가 발생합니다 : multiple types in one declaration typ

/** 
* 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 많은 오류를 얻을 : edef int32_t INT 라인 multi_types.h 파일은 다음과 같습니다.

내가 뭘 잘못하고 있니?

+0

어느 라인이 문제의 원인은? typedef? –

+0

예, typedef 줄입니다. – Vincent

답변

0

Thrift i32 유형을 int으로 typedefing하면 이름 충돌이 발생합니다.

그래서 해결책은 아니에 없음을 수행

namespace cpp another_tutorial 

// typedef i32 int - don't try this at home 

service MultiplicationService 
{ 
    i32 multiply(1 : i32 n1, 2 : i32 n2) 
}