0

2 つの数値を乗算する単純なリサイクル サーバーを作成しようとしています。

私はthriftファイルを次のように書きました:

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エラーが発生します。

私は何を間違っていますか?

4

1 に答える 1

0

Thrifti32型をに typedef しようとするとint、本質的に名前の衝突が発生します。

したがって、解決策はそれをしないことです:

namespace cpp another_tutorial

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

service MultiplicationService
{
    i32 multiply( 1 : i32 n1, 2 : i32 n2)
}
于 2014-12-01T00:12:48.513 に答える