building a statically linked version of memcached

1,343 views
Skip to first unread message

Harry Duin

unread,
Apr 16, 2010, 9:27:10 AM4/16/10
to memcached
I want to build a statically linked version of memcached, but am not
able to accomplish this. I got the dynamically linked version to build
right away. To get the static build, I did this:

1. configure --with-libevent=/data/webserver_pkgs/target/dist/
libevent/
2. update Makefile to add the parameter -static to the LDFLAGS

but that results in:

gcc -std=gnu99 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-
prototypes -Wmissing-declarations -Wredundant-decls -L/data/
webserver_pkgs/target/dist/libevent//lib -static -o memcached
memcached-memcached.o memcached-hash.o memcached-slabs.o memcached-
items.o memcached-assoc.o memcached-thread.o memcached-daemon.o
memcached-stats.o memcached-util.o memcached-cache.o -levent
memcached-memcached.o: In function `main':
/home/hduin/ots/memcached-1.4.5/memcached.c:4548: warning: Using
'getpwnam' in statically linked applications requires at runtime the
shared libraries from the glibc version used for linking
memcached-memcached.o: In function `server_socket':
/home/hduin/ots/memcached-1.4.5/memcached.c:3817: warning: Using
'getaddrinfo' in statically linked applications requires at runtime
the shared libraries from the glibc version used for linking
/data/webserver_pkgs/target/dist/libevent//lib/libevent.a(event.o): In
function `gettime':
/data/webserver_pkgs/target/extract/libevent-1.4.9-stable/event.c:150:
undefined reference to `clock_gettime'
/data/webserver_pkgs/target/dist/libevent//lib/libevent.a(event.o): In
function `detect_monotonic':
/data/webserver_pkgs/target/extract/libevent-1.4.9-stable/event.c:133:
undefined reference to `clock_gettime'
collect2: ld returned 1 exit status

Does anyone have a suggestion to make this work? Thanks,

Harry


--
Subscription settings: http://groups.google.com/group/memcached/subscribe?hl=en

Trond Norbye

unread,
Apr 16, 2010, 11:59:36 AM4/16/10
to memc...@googlegroups.com

On 16. apr. 2010, at 06.27, Harry Duin wrote:

> I want to build a statically linked version of memcached, but am not
> able to accomplish this. I got the dynamically linked version to build
> right away. To get the static build, I did this:
>
> 1. configure --with-libevent=/data/webserver_pkgs/target/dist/
> libevent/
> 2. update Makefile to add the parameter -static to the LDFLAGS
>

Add -lrt to LDFLAGS :)

Trond

Harry Duin

unread,
Apr 16, 2010, 1:48:53 PM4/16/10
to memcached
After adding -lrt I still see these errors:

memcached-memcached.o: In function `main':
/home/hduin/ots/memcached-1.4.5/memcached.c:4548: warning: Using
'getpwnam' in statically linked applications requires at runtime the
shared libraries from the glibc version used for linking
memcached-memcached.o: In function `server_socket':
/home/hduin/ots/memcached-1.4.5/memcached.c:3817: warning: Using
'getaddrinfo' in statically linked applications requires at runtime
the shared libraries from the glibc version used for linking
memcached-memcached.o: In function `update_event':
memcached.c:(.text+0x36a): undefined reference to `event_del'
memcached.c:(.text+0x387): undefined reference to `event_set'
memcached.c:(.text+0x392): undefined reference to `event_base_set'
memcached.c:(.text+0x3a4): undefined reference to `event_add'
memcached-memcached.o: In function `clock_handler':
memcached.c:(.text+0x43a): undefined reference to `event_set'
memcached.c:(.text+0x44b): undefined reference to `event_base_set'
memcached.c:(.text+0x458): undefined reference to `event_add'
memcached.c:(.text+0x46c): undefined reference to `event_del'
memcached-memcached.o: In function `conn_close':
memcached.c:(.text+0xc79): undefined reference to `event_del'
memcached-memcached.o: In function `conn_new':
memcached.c:(.text+0x1fe0): undefined reference to `event_set'
memcached.c:(.text+0x1fed): undefined reference to `event_base_set'
memcached.c:(.text+0x2003): undefined reference to `event_add'
memcached-memcached.o: In function `main':
memcached.c:(.text+0x4f02): undefined reference to `event_init'
memcached.c:(.text+0x5233): undefined reference to `event_base_loop'
memcached-thread.o: In function `setup_thread':
/home/hduin/ots/memcached-1.4.5/thread.c:193: undefined reference to
`event_init'
/home/hduin/ots/memcached-1.4.5/thread.c:200: undefined reference to
`event_set'
/home/hduin/ots/memcached-1.4.5/thread.c:202: undefined reference to
`event_base_set'
/home/hduin/ots/memcached-1.4.5/thread.c:204: undefined reference to
`event_add'
memcached-thread.o: In function `worker_libevent':
/home/hduin/ots/memcached-1.4.5/thread.c:245: undefined reference to
`event_base_loop'
collect2: ld returned 1 exit status


Trond Norbye

unread,
Apr 16, 2010, 3:38:39 PM4/16/10
to memc...@googlegroups.com

On 16. apr. 2010, at 10.48, Harry Duin wrote:

> After adding -lrt I still see these errors:
>

Did you remove -levent??

I did this by adding --disable-shared when building libevent, and then memcached with
./configure --with-libevent=<xxx> LDFLAGS=-lrt

Cheers

Trond

Harry Duin

unread,
Apr 19, 2010, 11:45:52 AM4/19/10
to memcached
I got this to work today as follows:

1. got latest libevent from: http://www.monkey.org/~provos/libevent/
2. build libevent as follows:
(cd in libevent directory first)
a. configure --prefix=/home/hduin/ots/libevent-1.4.13-build
b. make install
3. in latest memcached directory:
a. configure --with-libevent=/home/hduin/ots/libevent-1.4.13-build
b. edit Makefile and add -static to LDFLAGS and -lrt to LIBS
definitions
c. make

Based on these steps, I thought for sure that the following configure
would work so I would not need to edit the Makefile, but this did not
work. The configure fails on this: LIBS="-lrt" LDFLAGS="-static" ./
configure --with-libevent=/home/hduin/ots/libevent-1.4.13-build

Oh well, I got the static build!

Harry
> >> Subscription settings:http://groups.google.com/group/memcached/subscribe?hl=en- Hide quoted text -
>
> - Show quoted text -

Trond Norbye

unread,
Apr 19, 2010, 12:26:04 PM4/19/10
to memc...@googlegroups.com

On 19. apr. 2010, at 08.45, Harry Duin wrote:

> I got this to work today as follows:
>
> 1. got latest libevent from: http://www.monkey.org/~provos/libevent/
> 2. build libevent as follows:
> (cd in libevent directory first)
> a. configure --prefix=/home/hduin/ots/libevent-1.4.13-build

If you add: --disable-shared

> b. make install
> 3. in latest memcached directory:
> a. configure --with-libevent=/home/hduin/ots/libevent-1.4.13-build
> b. edit Makefile and add -static to LDFLAGS and -lrt to LIBS
> definitions
> c. make
>
> Based on these steps, I thought for sure that the following configure
> would work so I would not need to edit the Makefile, but this did not
> work.

It would have worked because it would not find a shared version of the library. Modern linkers will try to use a shared object if it finds one unless you tell it to use a static one.

Cheers,

Trond
Reply all
Reply to author
Forward
0 new messages