简体   繁体   English

在Windows中编译Apache Thrift服务

[英]Compiling Apache Thrift Service in Windows

I'm trying to build a thrift service on my windows machine. 我正在尝试在Windows计算机上构建节俭服务。 Im using cygwin and Netbeans IDE. 我正在使用cygwin和Netbeans IDE。 I've downloaded Thrift and built it trough cygwin and was able to successfully get Thrift to generate the server code for me, shown below. 我已经下载了Thrift并通过cygwin构建了它,并能够成功获取Thrift为我生成服务器代码,如下所示。

#include "Feed.h"
#include <protocol/TBinaryProtocol.h>
#include <server/TSimpleServer.h>
#include <transport/TServerSocket.h>
#include <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 feed;

class FeedHandler : virtual public FeedIf {
 public:
  FeedHandler() {
    // Your initialization goes here
  }

  void ping() {
    // Your implementation goes here
    printf("ping\n");
  }

  void search_text(search_resultset& _return, const std::string& query, const int32_t offset, const int32_t per_page) {
    // Your implementation goes here
    printf("search_text\n");
  }

  void search_prox_web(search_resultset& _return, const double lat, const double lon, const int32_t offset, const int32_t distance) {
    // Your implementation goes here
    printf("search_prox_web\n");
  }

  void search_prox_mob(search_resultset& _return, const double lat, const double lon, const int32_t offset, const int32_t distance) {
    // Your implementation goes here
    printf("search_prox_mob\n");
  }

  int32_t add_event(const std::string& name) {
    // Your implementation goes here
    printf("add_event\n");
  }

  int32_t associate_venue_with_event(const int32_t event_id, const int32_t venue_id, const int32_t usr_loc_id) {
    // Your implementation goes here
    printf("associate_venue_with_event\n");
  }

  int32_t save_usr_loc(const std::string& address) {
    // Your implementation goes here
    printf("save_usr_loc\n");
  }

};

int main(int argc, char **argv) {
  int port = 9090;
  shared_ptr<FeedHandler> handler(new FeedHandler());
  shared_ptr<TProcessor> processor(new FeedProcessor(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;
}

Then I built the libraries so I could compile and link my implementation. 然后,我构建了库,以便可以编译和链接我的实现。 The libraries built successfully, however when I try to compile I get the following error: 库成功构建,但是当我尝试编译时,出现以下错误:

build/Debug/Cygwin_4.x-Windows/main.o: In function `FeedProcessor': 
/cygdrive/c/Feed Service/Feed.h:930: undefined reference to `vtable for feed::FeedProcessor'
/cygdrive/c/Feed Service/Feed.h:930: undefined reference to `vtable for feed::FeedProcessor'
/cygdrive/c/Feed Service/Feed.h:931: undefined reference to `feed::FeedProcessor::process_ping(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
/cygdrive/c/Feed Service/Feed.h:932: undefined reference to `feed::FeedProcessor::process_search_text(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
/cygdrive/c/Feed Service/Feed.h:933: undefined reference to `feed::FeedProcessor::process_search_prox_web(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
/cygdrive/c/Feed Service/Feed.h:934: undefined reference to `feed::FeedProcessor::process_search_prox_mob(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
/cygdrive/c/Feed Service/Feed.h:935: undefined reference to `feed::FeedProcessor::process_add_event(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
/cygdrive/c/Feed Service/Feed.h:936: undefined reference to `feed::FeedProcessor::process_associate_venue_with_event(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
/cygdrive/c/Feed Service/Feed.h:937: undefined reference to `feed::FeedProcessor::process_save_usr_loc(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/feed_service.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 3s)

I thought these were all linker errors, so I did some googling and found a potential solution to add the following lines to the makefile: 我以为这些都是链接器错误,因此我进行了一些谷歌搜索,找到了一种可能的解决方案,将以下行添加到makefile中:

THRIFT_O=C:/cygwin/home/thrift/lib/cpp
    LTHRIFT=$(THRIFT_O)/Thrift.o $(THRIFT_O)/TSocket.o $(THRIFT_O)/TSimpleServer.o $(THRIFT_O)/TBufferTransports.o $(THRIFT_O)/TSimpleServer.o $(THRIFT_O)/TBinaryProtocol.o

and then link with $(LTHRIFT) rather than -lthrift. 然后链接$(LTHRIFT)而不是-lthrift。 However the file TBinaryProtocol.o doesn't seem to exist on my system. 但是,我的系统上似乎不存在文件TBinaryProtocol.o。 I tried re-building the libraries from source twice, and the file still isn't made. 我尝试从源代码重新构建库两次,但仍未创建文件。

First of all, is adding these lines to my makefile the correct solution to my initial problem? 首先,将这些行添加到我的makefile中是对我的最初问题的正确解决方案吗? Secondly, is the absence of TBinaryProtocol.oa major problem, or is it not created for a reason? 其次,是否缺少TBinaryProtocol.oa是主要问题,还是不是由于某种原因而创建的? If I do need it, is there a way I can make it individually or download it from somewhere? 如果我确实需要它,是否可以单独制作或从某个地方下载?

Edit: All of the include files are auto-generated by the Thrift compiler. 编辑:所有包含文件均由Thrift编译器自动生成。 I tried to include Feed.h here, but it is too big and goes over the character limit, so I included the portion that is referenced in the errors. 我试图在此处包括Feed.h,但它太大并且超出了字符数限制,因此我包括了错误中引用的部分。

class FeedProcessor : virtual public ::apache::thrift::TProcessor {
 protected:
  boost::shared_ptr<FeedIf> iface_;
  virtual bool process_fn(::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, std::string& fname, int32_t seqid, void* callContext);
 private:
  std::map<std::string, void (FeedProcessor::*)(int32_t, ::apache::thrift::protocol::TProtocol*, ::apache::thrift::protocol::TProtocol*, void*)> processMap_;
  void process_ping(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
  void process_search_text(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
  void process_search_prox_web(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
  void process_search_prox_mob(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
  void process_add_event(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
  void process_associate_venue_with_event(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
  void process_save_usr_loc(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
 public:
  FeedProcessor(boost::shared_ptr<FeedIf> iface) :
    iface_(iface) {
    processMap_["ping"] = &FeedProcessor::process_ping;
    processMap_["search_text"] = &FeedProcessor::process_search_text;
    processMap_["search_prox_web"] = &FeedProcessor::process_search_prox_web;
    processMap_["search_prox_mob"] = &FeedProcessor::process_search_prox_mob;
    processMap_["add_event"] = &FeedProcessor::process_add_event;
    processMap_["associate_venue_with_event"] = &FeedProcessor::process_associate_venue_with_event;
    processMap_["save_usr_loc"] = &FeedProcessor::process_save_usr_loc;
  }

  virtual bool process(boost::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot, boost::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot, void* callContext);
  virtual ~FeedProcessor() {}
};

Any help would be appreciated, I am very stuck on this. 任何帮助,我们将不胜感激。

Just for the sake of completeness: 仅出于完整性考虑:

(1) On Windows, there is no need to build the Thrift Compiler EXE on your own, there is a (small) installer to be downloaded here . (1) 在Windows上,不需要自己构建Thrift Compiler EXE ,这里有一个(小型)安装程序可供下载

(2) If you still want or need to build the Thrift Compiler Binaries, you still don't need to fire up Cygwin: More recent versions of Apache Thrift offer a nice Visual Studio solution which only require Win flex-bison as dependency. (2)如果仍然需要或需要构建Thrift编译器二进制文件,则仍然不需要启动Cygwin:较新版本的Apache Thrift提供了一个不错的Visual Studio解决方案 ,该解决方案仅需要Win flex-bison作为依赖项。 Works like a charm. 奇迹般有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM