Skip to content

Building and Using Thrift bindings for C with Cassandra

David Strauss edited this page May 6, 2013 · 2 revisions

Initial build environment

mkdir ~/c4ngx

Thrift compiler

cd ~/c4ngx
sudo yum install -y git gcc glib-devel flex # And more?
git clone http://git-wip-us.apache.org/repos/asf/thrift.git  # Using master because release 0.9.0 has path bugs for GLib bindings.
cd thrift
./bootstrap.sh  # Expect processor_test and concurrency_test warnings. Ignore them.
./configure --with-ruby=no --with-qt4=no --with-csharp=no --with-java=no --with-erlang=no --with-python=no --with-cpp=no --with-boost=no --with-php_extension=no --with-php=no --with-haskell=no --with-go=no --with-d=no
make

Cassandra Thrift bindings for C

cd ~/c4ngx
wget http://www.apache.org/dist/cassandra/1.2.4/apache-cassandra-1.2.4-bin.tar.gz
tar xzf apache-cassandra-1.2.4-bin.tar.gz
cd apache-cassandra-1.2.4/interface/
../../thrift/compiler/cpp/thrift --gen c_glib cassandra.thrift

Install the Thrift library

cd ~/c4ngx/thrift/
sudo make install

Using the generated bindings

Bindings are generated in ~/c4ngx/apache-cassandra-1.2.4/interface/gen-c_glib/. By default, "make install" for Thrift will use the "/usr/local" prefix. The following lines are useful with autotools:

# May need to run this: ./configure PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
PKG_CHECK_MODULES(GLIB, [ glib-2.0 >= 1.2 ])
PKG_CHECK_MODULES(THRIFT, [ thrift_c_glib >= 1.0.0-dev ] )

Revision notes

  • Paths for GLib bindings got fixed in commit e3da768367d0a3e013a00a5a365e58aed3bffa32.