本文簡述了Gearman::XS在Centos下編譯安裝方法,供大家參考學習一下!
目前Gearman能夠支援各種語言,其官網的描述如下:
Language Bindings/Drivers/FrameworksSelect 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/
在RHEL5.7下安裝的Gearman::XS,中間會出現各種問題,此處給出這些問題的解決方案供大家參考。
首先,我使用了cpanm來安裝Gearman::XS,結果如下:
[@localhost yunfei]# cpanm Gearman::XS--> Working on Gearman::XSFetching http://www.cpan.org/authors/id/K/KR/KROW/Gearman-XS-0.15.tar.gz ... OKConfiguring Gearman-XS-0.15 ... OKBuilding 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.ccc1: 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命令,就可以看到上面報的編譯錯誤了。ok,下面就著手解決它。
可以找到:
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 directoryXS.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 onceXS.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 castmake: *** [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的incule以及lib相關的東西。儲存退出Makefile,再次執行make,順利通過,然後make install就安裝完畢了。