Gearman::XS简介与安装背景
本文介绍了Gearman::XS在CentOS系统中的编译与安装流程,旨在为相关开发者提供实践参考。
Gearman目前兼容多种编程语言,其官方网站提供了详细的说明文档:
Language Bindings/Drivers/Frameworks
Select your language – cross links to download section which details all your options.
C, C#/.NET, Go, Java, Lisp, Nodejs, PHP, Perl, Python, Ruby, Database UDFs.
经过对C、Python和Perl三种语言API的实际测试,发现Perl版本的API功能相对更为完善。Gearman::XS即为Perl语言的开源扩展库,官方链接为:http://search.cpan.org/~krow/Gearman-XS/。
在RHEL 5.7环境下部署Gearman::XS的过程中,可能会遇到若干技术障碍,下文将针对这些常见问题给出解决方案。
首先尝试使用cpanm工具进行自动化安装,执行结果如下所示:
[@localhost yunfei]# cpanm Gearman::XS
--> Working on Gearman::XS
Fetching http://www.cpan.org/authors/id/K/KR/KROW/Gearman-XS-0.15.tar.gz ... OK
Configuring Gearman-XS-0.15 ... OK
Building and testing Gearman-XS-0.15 ... FAIL
! Installing Gearman::XS failed. See /root/.cpanm/work/1392343258.18128/build.log for details. Retry with --force to force install it.
显然,直接使用force参数强制安装并非长久之计,因此需要深入排查根本原因。通过查看日志文件 /root/.cpanm/work/1392343258.18128/build.log,发现了具体的错误提示:
gcc -c -Wall -Wundef -Wno-shadow -Wmissing-prototypes -fdiagnostics-show-option -Wformat=2 -Wstrict-aliasing -Wextra -Wmissing-declarations -Wcast-align -Wswitch-default -Wswitch-enum -Wno-undef -Wno-unused-value -Wno-unused-variable -Wno-unused-parameter -Wno-format-invalid-specifier -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DVERSION=\"0.15\" -DXS_VERSION=\"0.15\" -fPIC "-I/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE" XS.c
cc1: error: unrecognized command line option "-Wno-format-invalid-specifier"
make: *** [XS.o] Error 1
-> FAIL Installing Gearman::XS failed.
鉴于错误发生在编译阶段,建议切换至对应的源码构建目录(即 /root/.cpanm/work/1392343258.18128/)以便进一步调试。
cd /root/.cpanm/work/1392343258.18128/Gearman-XS-0.15
随后在该目录下执行make命令,即可复现前文所述的编译报错信息。接下来着手解决该问题。
vi Makefile
定位到以下配置项:
CCFLAGS = -Wall -Wundef -Wno-shadow -Wmissing-prototypes -fdiagnostics-show-option -Wformat=2 -Wstrict-aliasing -Wextra -Wmissing-declarations -Wcast-align -Wswitch-default -Wswitch-enum -Wno-undef -Wno-unused-value -Wno-unused-variable -Wno-unused-parameter -Wno-format-invalid-specifier
删除末尾的“-Wno-format-invalid-specifier”编译选项,保存修改后再次运行make。 此时会触发新的错误提示:
In file included from XS.xs:11:
gearman_xs.h:18:36: error: libgearman-1.0/gearman.h: No such file or directory
XS.c: In function 'XS_Gearman__XS_strerror':
XS.c:229: error: 'gearman_return_t' undeclared (first use in this function)
XS.c:229: error: (Each undeclared identifier is reported only once
XS.c:229: error: for each function it appears in.)
XS.c:229: error: expected ';' before 'rc'
XS.xs:82: warning: implicit declaration of function 'gearman_strerror'
XS.xs:82: error: 'rc' undeclared (first use in this function)
XS.xs:82: warning: assignment makes pointer from integer without a cast
make: *** [XS.o] Error 1
错误明确指出无法找到gearman.h文件,这意味着系统缺少gearman-devel包。通常情况下,直接通过yum安装gearman-devel即可解决此依赖问题。然而,由于当前RHEL系统采用的是手动编译安装的Gearman-1.1.11版本,与yum仓库中的版本不一致,因此需要再次打开并编辑Makefile文件。
定位到INC以及LDDLFLAGS变量,将其修改为以下内容:
LDDLFLAGS = -shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -L/usr/local/gearman/lib/ -lgearman
INC = -I/usr/local/gearman/include/ -L/usr/local/gearman/lib/
可以看出,主要改动在于添加了Gearman的头文件包含路径(include)以及库文件路径(lib)。保存Makefile后重新执行make,编译顺利通过,最后运行make install即可完成安装。