Mac上安装Thrift

本文详细介绍了如何在Mac上安装Thrift,包括基本需求、从SVN构建的额外需求、语言需求以及Boost和libevent的安装步骤。此外,还提供了使用Thrift进行多屏互动项目的Objective-C客户端和Java服务器的创建指南,包括创建Thrift文件、构建Objective-C应用和Java服务器的运行流程。
摘要由CSDN通过智能技术生成

现在在做一个多屏互动项目,需要Iphone设备与终端管理系统通信。

调研了下,决定使用Thrift框架实现通信模块。准备在Mac上安装Thrift,支持Objective-c和Java。

环境:Mac mini

Mac OS X Lion 10.7.5

1.安装Thrift

环境要求:http://wiki.apache.org/thrift/ThriftRequirements

Basic requirements

  • A relatively POSIX-compliant *NIX system
    • Cygwin or MinGW can be used on Windows
  • g++ 3.3.5+
  • boost 1.33.1+ (1.34.0 for building all tests)
  • Runtime libraries for lex and yacc might be needed for the compiler.

Requirements for building from SVN

  • GNU build tools: autoconf 2.59+ (2.60+ recommended), automake 1.9+, libtool 1.5.24+
  • pkg-config autoconf macros (pkg.m4) (Use MacPorts for Mac OS X)

  • lex and yacc (developed primarily with flex and bison)
  • libssl-dev

Language requirements

  • C++
    • Boost 1.33.1+
    • libevent (optional, to build the nonblocking server)
    • zlib (optional)
  • Java
    • Java 1.5+
    • Apache Ant
    • Apache Ivy (recommended)
    • Apache Commons Lang (recommended)
    • SLF4J
  • C#: Mono 1.2.4+ (and pkg-config to detect it) or Visual Studio 2005+
  • Python 2.4+ (including header files for extension modules)
  • PHP 5.0+ (optionally including header files for extension modules)
  • Ruby 1.8+ (including header files for extension modules)
  • Erlang R12 (R11 works but not recommended)
  • Perl 5
    • Bit::Vector
    • Class::Accessor

安装方法:http://wiki.apache.org/thrift/GettingOsxPackages

Install Boost

Download the boost library and bjam installer from http://www.boost.org Untar and place bjam in the boost folder and then compile with

$ sudo ./bjam toolset=darwin link=shared threading=multi runtime-link=shared variant=release address-model=64 stage install

Install libevent

Download libevent from http://monkey.org/~provos/libevent/ untar and compile with

$ ./configure --prefix=/usr/local --disable-static
$ make
$ sudo make install

Install Apache Thrift

Download apache thrift from http://thrift.apache.org untar and compile with

$ ./configure --prefix=/usr/local/ --disable-static --with-boost=/usr/local --with-libevent=/usr/local --without-python --without-csharp --without-ruby --without-perl --without-php --without-haskell --without-erlang
$ make
$ sudo make install


安装完完后,执行文件为/usr/local/bin/thrift


2.使用

http://wiki.apache.org/thrift/ThriftUsageObjectiveC

Getting started

This tutorial will walk you through creating a sample project which is a bulletin board application using Thrift. It consists of an iOS client app written in Objective-C and a Java server. It is assumed that you will have a basic knowledge of Objective-C and Xcode to complete this tutorial. Note that the client runs on Mac OS with small modification.

align=right

Acknowledgment: A part of this tutorial was borrowed from newacct's tutorial.

Sample Download

You can download the sample project from here. It includes:

  • The whole myThriftApp project
  • the runtime library in thrift/ directory from 0.8.0-dev (You should replace this with the latest one.)
  • idl.thrift
  • Server.java and BulletinBoard.java in gen-java/ directory

Requirements

Make sure that your system meets the requirements as noted in ThriftRequirements.

  • Thrift 0.9.0+ (0.8.0-dev+)
  • iOS 4+ or Mac OS X 10.5+
  • Xcode 4.2+

The following are required for the Java server; but, not the Objective-C client.

Creating the Thrift file

We will use a simple thrift IDL file, myThriftApp/idl.thrift. This defines a bulletin board service. You can upload your message and date using add() method. get()method returns a list of the struct so that we demonstrate how to send/receive an array of structs in Objective-C.

// idl.thrift
struct Message {
     1: string text,
     2: string date
}

service BulletinBoard {
    void add(1: Message msg),
    list<Message> get()

}

  • Run the thrift compiler to generate the stub files (e.g. gen-cocoa/idl.h and gen-cocoa/idl.m).
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值