Компиляция Apache Thrift Service в Windows - PullRequest
1 голос
/ 16 ноября 2011

Я пытаюсь создать экономичный сервис на моей машине с Windows. Я использую Cygwin и Netbeans IDE. Я скачал 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;
}

Затем я собрал библиотеки, чтобы можно было скомпилировать и связать мою реализацию. Библиотеки построены успешно, однако при попытке компилирования я получаю следующую ошибку:

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)

Я думал, что это все ошибки компоновщика, поэтому я немного погуглил и нашел потенциальное решение для добавления следующих строк в make-файл:

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

, а затем связать с $ (LTHRIFT), а не -lthrift. Однако файл TBinaryProtocol.o, похоже, не существует в моей системе. Я дважды пытался пересобрать библиотеки из исходного кода, но файл все еще не создан.

Прежде всего, добавляет ли эти строки в мой make-файл правильное решение моей первоначальной проблемы? Во-вторых, является ли отсутствие TBinaryProtocol.o серьезной проблемой или оно не создано по какой-то причине? Если мне это нужно, есть ли способ сделать это по отдельности или скачать откуда-нибудь?

Редактировать: Все включаемые файлы автоматически генерируются компилятором Thrift. Я попытался включить 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() {}
};

Буду признателен за любую помощь, я очень застрял в этом.

1 Ответ

0 голосов
/ 25 августа 2013

Просто для полноты:

(1) В Windows нет необходимости собирать Thrift Compiler EXE самостоятельно, есть (маленький) установщик для загрузки здесь .

(2) Если вам все еще нужно или вам нужно создать бинарники Thrift Compiler, вам все равно не нужно запускать Cygwin: более поздние версии Apache Thrift предлагают отличное решение Visual Studio которые требуют только Win flex-bison в качестве зависимости.Работает как шарм.

...