when i run the libmemcached example code on my ubuntu, it gave me the error "undefined reference to `memcached_create'", anyone can help ? thanks
#include <libmemcached/memcached.h>
int main(int ar开发者_StackOverflow中文版gc, char **argv) {
//memcached_servers_parse (char *server_strings);
memcached_server_st *servers = NULL;
memcached_st *memc;
memcached_return rc;
char *key= "keystring";
char *value= "keyvalue";
memc= memcached_create(NULL);
servers= memcached_server_list_append(servers, "localhost", 11211, &rc); rc= memcached_server_push(memc, servers);
if (rc == MEMCACHED_SUCCESS)
fprintf(stderr,"Added server successfully\n"); else
fprintf(stderr,"Couldn't add server: %s\n",memcached_strerror(memc, rc));
rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0);
if (rc == MEMCACHED_SUCCESS)
fprintf(stderr,"Key stored successfully\n"); else
fprintf(stderr,"Couldn't store key: %s\n",memcached_strerror(memc, rc));
return 0;
}
Pass -lmemcached
to GCC. This tells it to link to the libmemcached.so
shared library.
- open your terminal and change directory to your libmemcached which is uncompressed.
- type
./configure
- type
make
- in your C project, Right click and select "Properties". In "linker" add "libmemcached.so" library and remember to add Library directory (links to your directory contains libmemcached.so).
When I built the library (libmemcached), it only builds the static library and when I am linking my program ( mentioned above ), it gives me
$ gcc MyMemClient.c -o MyMemClient -L/usr/local/lib/libmemcached.a
/tmp/ccQEXVjv.o:MyMemClient.c:(.text+0x1f): undefined reference to `_memcached_create'
/tmp/ccQEXVjv.o:MyMemClient.c:(.text+0x58): undefined reference to `_memcached_server_list_append'
//ccQEXVjv.o:MyMemClient.c:(text+0x6d): undefined reference to `_memcached_server_push'
/tmp/ccQEXVjv.o:MyMemClient.c:(.text+0xc1): undefined reference to `_memcached_strerror'
/tmpccQEXVjv.o:MyMemClient.c:(.text+0x12a): undefined reference to `_memcached_set'
/tmp/ccQEXVjv.o:MyMemClient.c:(.text+0x170): undefined reference to `_memcached_strerror'
/tmp/ccQEXVjv.o:MyMemClient.c:(.text+0x199): undefined reference to `_memcached_server_free'
//ccQEXVjv.o:MyMemClient.c:(.text+0x1a4): undefined reference to `_memcached_free'
ld returned 1 exit status
精彩评论