Compile cmemcache on Gentoo

I needed to install cmemcache on a Gentoo box in order to enable Django to work with memcached. But when I tried to compile the cmemcache code, I got such error messages:

‘CmemcacheObject’ has no member named ‘mc_ctxt’

I’m surprised Google didn’t give me many answers. But I came across this post which was very useful. So in the end, here’s how I got cmemcache compiled and installed on Gentoo.

cd ~/code
sudo emerge libmemcache
wget http://gijsbert.org/downloads/cmemcache/libmemcache-1.4.0.rc2.patch
wget http://gijsbert.org/downloads/cmemcache/cmemcache-0.95.tar.bz2
# the patch was made using a folder called reference
mkdir reference
cd reference
tar xjvf ../libmemcache-1.4.0.rc2.tar.bz2
cd ..
patch -p0 < libmemcache-1.4.0.rc2.patch
cd reference/libmemcache-1.4.0.rc2
./configure && make
sudo make install
cd ../../
tar xjvf cmemcache-0.95.tar.bz2
cd cmemcache-0.95
sudo python setup.py install