编译libmemcached

Posted JohnGu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编译libmemcached相关的知识,希望对你有一定的参考价值。

php的扩展memcache,不支持cas,所以我们要装memcached扩展,memcached扩展是基于libmemcached,所以要先安装libmemcached

 

一、下载软件

1、libmemcached下载地址:https://launchpad.net/libmemcached/+download

文件:memcached-2.2.0.tgz

2、php-memcached下载地址:http://pecl.php.net/package/memcached

文件:libmemcached-1.0.18.tar.gz 

 

二、安装libmemcached

[[email protected] local]# mkdir -p libmemcached
[[email protected] local]# tar zxvf libmemcached-1.0.18.tar.gz 
[[email protected] local]# cd libmemcached-1.0.18
[[email protected] libmemcached-1.0.18]# ./configure --prefix=/usr/local/libmemcached --with-memcached
[[email protected] libmemcached-1.0.18]# make
[[email protected] libmemcached-1.0.18]# make install

 

三、安装php-memcached

[[email protected] local]# mkdir -p phpmemcached 
[[email protected] local]# tar zxvf memcached-2.2.0.tgz
[[email protected] local]# cd memcached-2.2.0
[[email protected] memcached-2.2.0]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[[email protected] memcached-2.2.0]# ./configure --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached
-sasl
[[email protected] memcached-2.2.0]# make
[[email protected] memcached-2.2.0]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
[[email protected] memcached-2.2.0]# ll /usr/local/php/lib/php/extensions/no-debug-zts-20131226/

total 2140
-rwxr-xr-x. 1 root root 325608 Dec 30 15:59 memcached.so
-rwxr-xr-x. 1 root root 453766 Dec 30 17:44 memcache.so
-rwxr-xr-x. 1 root root 540834 Dec 19 15:38 opcache.so
-rwxr-xr-x. 1 root root 861055 Dec 30 16:47 redis.so

[[email protected] memcached-2.2.0]# vi + /usr/local/php/lib/php.ini
加上extension=memcached.so
[[email protected] memcached-2.2.0]# /usr/local/apache2/bin/apachectl restart
查看phpinfo可以看到支持了

技术分享图片

 

四、安装遇到的问题
1、安装libmemcached过程中不要忘了,--with-memcached,不然会提示你

checking for memcached... no
configure: error: "could not find memcached binary"

2、你的memcached是不是1.2.4以上的,如果不是会提示你

clients/ms_thread.o: In function `ms_setup_thread‘:
/home/zhangy/libmemcached-0.42/clients/ms_thread.c:225: undefined reference to `__sync_fetch_and_add_4‘
clients/ms_thread.o:/home/zhangy/libmemcached-0.42/clients/ms_thread.c:196: more undefined references to `__sync_fetch_and_add_4‘ follow
collect2: ld returned 1 exit status
make[2]: *** [clients/memslap] Error 1
make[2]: Leaving directory `/home/zhangy/libmemcached-0.42‘

解决办法是--disable-64bit CFLAGS="-O3 -march=i686",如果不用这个64位的long型数据,我想php扩展memcached,memcache也就没什么区别了,装memcached也就没什么意思了。

 
 
































以上是关于编译libmemcached的主要内容,如果未能解决你的问题,请参考以下文章

交叉编译,为什么需要交叉编译

class文件反编译后,怎么编译回去!

驱动编译进内核和编译模块的区别

Linux——Linux驱动之Makefile编译总结(编译器路径设置编译流程分析编译试验测试)

Linux——Linux驱动之Makefile编译总结(编译器路径设置编译流程分析编译试验测试)

GCC编译器原理------编译原理三:编译过程(2-1)---编译之词法分析