Installing Thrift on Snow Leopard

Introduction

Yesterday I spent the day with Thrift. Thrift is a framework developed at Facebook for “gluing” together programming languages. The Thrift framework enables efficient and scalable communication between C++, Java, Python, PHP, XSD, Ruby, C#, Perl, Objective C, Erlang, Smalltalk, OCaml, and Haskell. Thrift allows you to chose the right programming language for the job at hand. With Thrift you won’t have to chose between development speed and performance – you can have your cake and eat it too. If you are an employer, you can relax language restraints and focus on finding the smartest people. Thrift is still very much in its infancy, and documentation on getting it to work is sparse. I hope to shed some light on Thrift and make it just a little bit easier to get up and running. This post will focus on installing Thrift. I will write a follow-up post on how to use Thrift to communicate between PHP and C++.

Why Thrift?

If Thrift is still very new and lacks documentation – why bother learning it? Especially when there are more mature alternatives like Google’s Protocol Buffer and SOAP. The answer depends on your requirements. I write web-based financial applications. I use PHP as my server-side scripting language, and C++ for the heavy-lifting. As of this writing, Protocol Buffer does not support PHP, and the SOAP protocol has too much overhead for the high-speed finance world. Furthermore, I think Thrift has more potential than both alternatives and will gain in popularity as more people learn it. Also apparently Thrift was developed by Google engineers working at Facebook who missed using Protocol Buffer, so they re-built it and expanded its feature set. You can find more information on the differences between Thrift and Protocol Buffer at: https://stuartsierra.com/2008/07/10/thrift-vs-protocol-buffers.

Installation

I will be first to say that installing Thrift was a pain. I spent about four hours getting everything to work. However, most of this time was spent finding up-to-date information. I hope to get you up in running in less than an hour. This tutorial is aimed for Snow Leopard users, but I’m sure it would apply to Leopard developers as well. I am assuming you have Xcode installed. I will also say that I am not a Unix expert – this build worked for me – I am not entirely sure about the current state of my computer (ie. what dependencies I installed in the past), but I will try to make this tutorial as generic as possible. First we’ll need to install a few dependencies before we can start installing Thrift. Update: Do not try and install these dependencies or thrift using macports. There are some inconsistencies with the macport builds. (Thanks Jonathan!)

Installing Boost

Boost is a set of C++ libraries that Thrift depends on. You can download it at: https://www.boost.org/users/download/. I downloaded Version 1.41.0. Once it’s downloaded, you’ll need to unzip it. For this I just use The Unarchiver, but using the gzip terminal command works too.
Now we’ll use the information provided with the install to build Boost, you can find that information by navigating to the unzipped boost directory and going to: index.html > “Getting Started Guide” > “Getting Started on Unix variants (e.g. Linux, Mac OS)” > “5.1 Easy Build and Install” The steps described in the documentation are as follows:

sudo ./bootstrap.sh
sudo ./bjam install

The install will take a while! This is a good time to take a break from your computer – grab a coffee, do some push-ups. Once Thrift is all set up you’ll have plenty of time to soak up the LCD rays… back with a sweat? Great! Well, that should do it. You should find evidence of boost in: /usr/local/include/ and /usr/local/lib/.

Installing libevent

The next dependency we’ll need is libevent. Libevent is an over-the-network event notification API. Now that’s a mouthful.. I’m pretty sure Thrift uses it to do client / server communication between the programming languages. The good news is you won’t have any time to exercise – this is a quick build. Download libevent from: https://monkey.org/~provos/libevent/. I downloaded libevent-1.4.13-stable.tar.gz. Navigate to where you downloaded it, unzip it, cd into the unzipped directory, the run the following commands:

./configure
make
sudo make install

I’m not entirely sure where the build ends up, but Thrift will yell at you if something went wrong so let’s move on.

Installing Thrift

Alright! We’re so close. Let’s install thrift. You can download thrift from https://incubator.apache.org/thrift/download/. I downloaded thrift-incubating-0.2.0.tar.gz. After it finishes downloading, unzip it, navigate into the directory and run the following commands:

./bootstrap.sh
./configure --with-boost=/usr/local/include/
make
sudo make install

And you’re done! You will find the thrift build in /usr/local/bin You should be able to run thrift from the terminal.

Conclusion

Now that wasn’t too bad! If you have any problems with building anything do not hesitate to ask – I will do my best to answer your questions. Stay tuned for the next article on how to establish communication between PHP and C++ using Thrift!

Comments

Jonathan

Wednesday, January 20th, 2010

Great Tutorial, Thanks a bunch! Just to help anyone else reading this, - don't use macports to get the sources (there are quite a few version inconsistencies i've encountered) - if you have python that you downloaded in /Library/Frameworks/Python.framework even though it maybe the same version as the one included in OSX, i encountered build errors when thrift was building the python packages Just follow this article completely and you should be set! Thank you!!

Matt Mueller

Wednesday, January 20th, 2010

I'm glad everything worked out for you! Yah, I've stopped using macports because I find its often more trouble than its worth! I'll update the tutorial to include your advice. Thanks!

Chok Ooi

Monday, March 1st, 2010

Hi, I have no problems running ./bootstrap.sh and ./configure for Thrift. However, when I run make, I get the following error. I am on Snow Leopard. I cannot find any site that mentioned this issue. Appreciate your feedback. libtool: Version mismatch error. This is libtool 2.2.4, but the libtool: definition of this LT_INIT comes from libtool 2.2.6. libtool: You should recreate aclocal.m4 with macros from libtool 2.2.4 libtool: and run autoconf again. make[3]: *** [thrift] Error 63 make[2]: *** [all] Error 2 make[1]: *** [all-recursive] Error 1 make: *** [all] Error 2

Jerry You

Friday, March 5th, 2010

I got same error about the mismatch of libtool version. The fix is to download the latest Thrift from https://instant.thrift-rpc.org/

Vlady

Friday, May 7th, 2010

Hi, when I run bootstrap.sh.. i get this... ~/coder/thrift-0.2.0]$./bootstrap.sh glibtoolize: You should add the contents of `./aclocal/libtool.m4' to `aclocal.m4'. glibtoolize: You should add the contents of `./aclocal/ltoptions.m4' to `aclocal.m4'. glibtoolize: You should add the contents of `./aclocal/ltsugar.m4' to `aclocal.m4'. glibtoolize: You should add the contents of `./aclocal/ltversion.m4' to `aclocal.m4'. glibtoolize: You should add the contents of `./aclocal/lt~obsolete.m4' to `aclocal.m4'. any suggestions?

Ranjith

Saturday, June 5th, 2010

Hey...I'm this close to getting the thrift installed. I too spent a whole day before stumbling to this site...my basic problem was not having xcode installed properly....I was missing all gcc and make commands....now got boost, libeven and ran ./bootstrap.sh....but when I run ./configure, I get this error at the very end...../configure: line 16615: syntax error near unexpected token `MONO,' ./configure: line 16615: ` PKG_CHECK_MODULES(MONO, mono >= 2.0.0, net_3_5=yes, net_3_5=no)'

Dheeraj Goswami    •   https://website

Friday, August 13th, 2010

This is because you dont have correct pkg.m4 file. Do the following If you don't have "MacPorts":https://www.macports.org/, install it. T sudo port install pkgconfig Go to your thrift root directory cp /opt/local/share/aclocal/pkg.m4 aclocal/ Run the following again ./bootstrap.sh ./configure make sudo make install

George Calm    •   https://georgecalm.com

Tuesday, October 5th, 2010

Very helpful post. Thanks!

Ben Fraser

Thursday, November 4th, 2010

Thanks, this was very helpful. I followed exactly except up to the actual download of thrift. The link didn't have the 0.2.0 version, so I downloaded the 0.5.0 version. The only difference is that you don't need to do the ./bootstrap.sh command and can go straight to to the ./configure command.