Thursday, July 9, 2015

Building Memcached with Statically-Linked Libevent

Building memcached with statically-linked libevent is not quite complicated. However, I found out that we have to make slight adjustment to memcached build system and header. In some scenario, statically linking memcached to libevent is the preferred solution in order to remove the headache associated with maintaining different versions of memcached-libevent combination.

Well, actually, I have a working combination of memcached 1.4.24 and libevent 2.0.22-stable. But, it's very dirty at the moment. I'll eventually release it in Github.

Anyway, these are what you need to do to make memcached linked into statically built libevent:
  1. Place libevent source code inside memcached root directory (the next steps assumes you placed libevent source code inside memcached root directory).
  2. Make the libevent code statically built by using LT_INIT([disable-shared]) in its configure.ac
  3. Make memcached only link to libevent_core.la in memcached Makefile.am. Nothing more than that, because that's all it needs.
  4. Add AC_CONFIG_SUBDIRS([your_libevent_dir]) to memcached configure.ac. 
  5. Disable/remove support for dynamically-linked libevent from memcached configure.ac. 
  6. In my particular memcached version, I need to modify memcached.h to add two additional libevent include files to make it compile-able, i.e. event_struct.h and event_compat.h. 
Hopefully, this is enough as hints for those wanting to statically link libevent to memcached. I'll update this post once the code is up in GitHub.

Post a Comment

No comments: