Mac上安装Thrift

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

现在在做一个多屏互动项目,需要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-coc
### 安装和配置Thrift #### 准备工作 为了在Mac OS上为IntelliJ IDEA安装和配置Thrift,需先确认已安装必要的开发环境组件。这包括但不限于JDK 1.6以上版本以及Scala环境[^1]。 #### 安装Thrift 对于Mac操作系统而言,推荐采用Homebrew来简化软件包管理过程。通过终端执行`brew install thrift`可以轻松完成Thrift安装操作[^4]。此方式不仅便捷而且能够自动处理依赖关系,确保所使用的Thrift版本是最新的稳定发行版。 #### 配置环境变量 成功安装后,应将Thrift路径加入系统的环境变量中以便于全局调用。编辑`.bash_profile`或适用于当前shell类型的启动脚本(如zsh则修改`.zshrc`),添加如下两行: ```bash export THRIFT_HOME=/usr/local/opt/thrift/libexec export PATH=$PATH:$THRIFT_HOME/bin ``` 随后运行`source ~/.bash_profile`(如果是其他Shell,则对应调整)让更改立即生效,并可通过`thrift --version`验证是否正确设置了Thrift环境[^3]。 #### IntelliJ IDEA中的Thrift支持 针对IDEA本身,虽然官方并未提供专门面向Thrift的支持插件,但是可以通过集成Maven项目的方式间接实现对Thrift文件的良好支持。具体做法是在项目的pom.xml里引入相应的编译器依赖项,从而允许开发者编写、调试基于Thrift定义的服务接口[^2]。 另外值得注意的是,当涉及到跨平台兼容性问题时——特别是苹果转向ARM架构处理器的情况下——可能遇到某些原生库缺失的问题;此时应当关注社区反馈并尝试寻找替代方案或是等待官方更新解决此类障碍。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值