设为首页 收藏本站
查看: 1188|回复: 0

[经验分享] Memcached 编译安装

[复制链接]

尚未签到

发表于 2015-9-1 08:11:44 | 显示全部楼层 |阅读模式
  http://ihacklog.com/linux/memcached-compilation.html
  Memcached :1.4.5
  libevent-1.4.13-stable
  Linux ubuntu 3.2.0-23-generic 64位 Server版本
  gcc 4.6.3

1
2
3
4
5

wget http://memcached.org/latest
tar -xvzf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure
sudo make
  报错:
  make all-recursive
make[1]: Entering directory `/usr/local/src/memcached-1.4.5′
Making all in doc
make[2]: Entering directory `/usr/local/src/memcached-1.4.5/doc’
make all-am
make[3]: Entering directory `/usr/local/src/memcached-1.4.5/doc’
make[3]: Nothing to be done for `all-am’.
make[3]: Leaving directory `/usr/local/src/memcached-1.4.5/doc’
make[2]: Leaving directory `/usr/local/src/memcached-1.4.5/doc’
make[2]: Entering directory `/usr/local/src/memcached-1.4.5′
gcc -std=gnu99 -DHAVE_CONFIG_H -I. -DNDEBUG -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached-memcached.o -MD -MP -MF .deps/memcached-memcached.Tpo -c -o memcached-memcached.o `test -f ‘memcached.c’ || echo ‘./’`memcached.c
memcached.c: In function ‘complete_incr_bin’:
memcached.c:1023:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c:1044:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c:1061:17: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c: In function ‘process_bin_get’:
memcached.c:1193:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c: In function ‘process_bin_update’:
memcached.c:1889:5: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c:1905:5: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c: In function ‘process_bin_append_prepend’:
memcached.c:1949:5: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c: In function ‘process_bin_delete’:
memcached.c:2014:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c: In function ‘do_store_item’:
memcached.c:2127:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c:2127:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c:2144:25: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c:2145:25: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c:2158:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c:2160:17: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c:2160:17: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c:2202:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c:2214:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c: In function ‘process_get_command’:
memcached.c:2592:45: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c: In function ‘process_update_command’:
memcached.c:2751:5: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c: In function ‘do_add_delta’:
memcached.c:2870:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
memcached.c: In function ‘main’:
memcached.c:4630:13: error: variable ‘udp_port’ set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
  make[2]: *** [memcached-memcached.o] Error 1
make[2]: Leaving directory `/usr/local/src/memcached-1.4.5′
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/memcached-1.4.5′
make: *** [all] Error 2
  解决办法,打补丁:


1
2

sudo wget http://johntech-resource.googlecode.com/files/fix-strict-aliasing.patch
sudo patch memcached.h fix-strict-aliasing.patch
  如果不打补丁的话,这里也有个解决办法:
http://d.hatena.ne.jp/rougeref/comment?date=20100818
即CFLAGS里的-Werror选项去掉(-Werror 将所有警告转换为错误):


1
2
3
4
5

$ diff configure configure.bak
7917c7917
<   CFLAGS="$CFLAGS -Wall -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls"
---
>   CFLAGS="$CFLAGS -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls"
  再make ,又报错了:
  memcached.c: In function ‘main’:
memcached.c:4630:13: error: variable ‘udp_port’ set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
  items.c: In function ‘do_item_stats_sizes’:
items.c:453:21: error: variable ‘klen’ set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
  解决办法:


1

sudo vim Makefile
  添加 “-Wno-error=unused-but-set-variable” 到 CFLAGS.


1
2

sudo make && sudo make test
sudo make install
  OK,这下终于通过了。
之所以出这个错误是因为Makefile里面指定了C99的标准。
  MORE(以下摘自WWW):
  warning: dereferencing type-punned pointer will break strict-aliasing rules
  在 gcc 2.x 下编译没有任何 warning 信息的代码换到 gcc 3.x 版本下之后出现了类似的 warning 。原因是 gcc 3 引入了 strict aliasing 架构,当编译时使用了 -fstrict-aliasing 参数(该参数在使用了 -O2 , -O3, -Os 优化参数的情况下默认生效),而源代码中存在一些违反了 strict-aliasing 规则的地方的话,编译器就会对这部分代码提出 warning 。
  gcc 3 manual 对于 -fstrict-aliasing 参数的说明是:Allows the compiler to assume the strictest aliasing rules applicable to the language being compiled. For C (and C++), this activates optimizations based on the type of expressions. In particular, an object of one type is assumed never to reside at the same address as an object of a different type, unless the types are almost the same. For example, an “unsigned int” can alias an “int”, but not a “void*” or a “double”. A character type may alias any other type.
  简而言之, 在该参数激活的情况下,编译器希望不同类型的对象不会指向同一个地址。比如像这段代码:


1
2
3

int retLen;
someSetFunc((unsigned long *)&retLen);
printf ("ret len = %d\n" ,retLen);
  由于 someSetFunc 的传入参数类型定义为 unsigned long ,所以需要进行这样的指针类型强制 cast 。但对于 -fstrict-aliasing 优化参数来说,这样的转换是有潜在问题的(但实际上可能并不会造成任何问题)。所以如果现有的源代码存在太多这样的类型强制转换的问题的话,对这些代码进行修改也许会是场噩梦。最简单的方法是使用 -fno-strict-aliasing 参数来关闭 gcc 的优化选项,代价是放弃了 strict-aliasing 编译优化可能带来的可执行代码的性能提升。当然也可以用 -Wno-strict-aliasing 来屏蔽相关的 warning 信息,但无论这些 warning 信息多么的无关紧要,总还是“疑似危险”,所以可能的话最好还是把所有的 warning 都消灭掉。
  消灭的方法也不算复杂,正如 gcc manual 所示的那样,可以是采用 union 的不同成员变量来完成类型的转换。上面那段代码可以改为:


1
2
3
4
5
6
7

union u_retLen
{
int retLen;
unsigned long ptr;
};
someSetFunc(&u_retLen.ptr);
printf ("ret len = %d\n" ,u_retLen.retLen);
  虽然会使源代码变得丑陋,但对于大部分已有的源代码来说,这可能是改动最小的方案了。而对于新写的代码来说,如何更好的设计函数的入口参数(比如使用 void*)可能才是需要去思考的问题了。
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-108106-1-1.html 上篇帖子: 原创:.NET版分布式缓存Memcached测试实例(Memcached缓存读取添加与清空等) 下篇帖子: [教程]centos下安装memcached并设置开机自动启动-两种方法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表