Linux下編譯安裝PCRE庫

haojw 8年前發布 | 28K 次閱讀 Linux

來自: http://chenzhou123520.iteye.com/blog/1817563


最近在學習nginx,nginx rewrite依賴于PCRE庫,所以需要在linux系統中編譯安裝PCRE庫。具體步驟如下:

 

1.下載PCRE包

首先去官網下載pcre的安裝包

如果通過FTP的方式,下載地址為:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

如果通過http的方式,下載地址為:http://sourceforge.net/projects/pcre/files/pcre/

目前最新的版本為8.32,linux對應的安裝包名稱為:pcre-8.32.tar.gz。

 

2.把安裝包上傳到服務器,然后解壓

Shell代碼  收藏代碼

  1. [root@localhost local]# tar -zxvf pcre-8.32.tar.gz  

 

解壓之后在當前目錄下生成了一個文件夾:pcre-8.32

Shell代碼  收藏代碼

  1. drwxr-xr-x 7 1169  1169    4096 Nov 30 18:50 pcre-8.32  

 

3.配置

Shell代碼  收藏代碼

  1. [root@localhost pcre-8.32]# ./configure  

配置完之后控制臺會打印出pcre配置的摘要信息

Shell代碼  收藏代碼

  1. pcre-8.32 configuration summary:  

  2.   

  3.     Install prefix .................. : /usr/local  

  4.     C preprocessor .................. : gcc -E  

  5.     C compiler ...................... : gcc  

  6.     C++ preprocessor ................ : g++ -E  

  7.     C++ compiler .................... : g++  

  8.     Linker .......................... : /usr/bin/ld  

  9.     C preprocessor flags ............ :   

  10.     C compiler flags ................ : -O2 -fvisibility=hidden  

  11.     C++ compiler flags .............. : -O2 -fvisibility=hidden -fvisibility-inlines-hidden  

  12.     Linker flags .................... :   

  13.     Extra libraries ................. :   

  14.   

  15.     Build 8 bit pcre library ........ : yes  

  16.     Build 16 bit pcre library ....... : no  

  17.     Build 32 bit pcre library ....... : no  

  18.     Build C++ library ............... : yes  

  19.     Enable JIT compiling support .... : no  

  20.     Enable UTF-8/16/32 support ...... : no  

  21.     Unicode properties .............. : no  

  22.     Newline char/sequence ........... : lf  

  23.     \R matches only ANYCRLF ......... : no  

  24.     EBCDIC coding ................... : no  

  25.     EBCDIC code for NL .............. : n/a  

  26.     Rebuild char tables ............. : no  

  27.     Use stack recursion ............. : yes  

  28.     POSIX mem threshold ............. : 10  

  29.     Internal link size .............. : 2  

  30.     Match limit ..................... : 10000000  

  31.     Match limit recursion ........... : MATCH_LIMIT  

  32.     Build shared libs ............... : yes  

  33.     Build static libs ............... : yes  

  34.     Use JIT in pcregrep ............. : no  

  35.     Buffer size for pcregrep ........ : 20480  

  36.     Link pcregrep with libz ......... : no  

  37.     Link pcregrep with libbz2 ....... : no  

  38.     Link pcretest with libedit ...... : no  

  39.     Link pcretest with libreadline .. : no  

  40.     Valgrind support ................ : no  

  41.     Code coverage ................... : no  

 

4.編譯

執行make操作:

Shell代碼  收藏代碼

  1. [root@localhost pcre-8.32]# make  

 編譯完后可以執行make check進行測試(這一步非必須)

Shell代碼  收藏代碼

  1. Testing pcregrep version 8.32 2012-11-30  

  2. Testing pcregrep main features  

  3. Skipping pcregrep UTF-8 tests: no UTF-8 support in PCRE library  

  4. Testing pcregrep newline settings  

  5. PASS: RunGrepTest  

  6. ==================  

  7. All 5 tests passed  

  8. ==================  

  9. make[2]: Leaving directory `/usr/local/pcre-8.32'  

  10. make[1]: Leaving directory `/usr/local/pcre-8.32'  

  11. [root@localhost pcre-8.32]#   

 上面的make check結果中有一句:

Shell代碼  收藏代碼

  1. Skipping pcregrep UTF-8 tests: no UTF-8 support in PCRE library  

 這是因為在前面步驟中執行./configuration配置時沒有加上對utf-8的支持

如果要加上對utf-8的支持可以在./configuration時加上參數:

Shell代碼  收藏代碼

  1. [root@localhost pcre-8.32]# ./configure --enable-utf8  

 配置完后再重新make

make完后再次執行make check結果如下:

Shell代碼  收藏代碼

  1. Testing pcregrep version 8.32 2012-11-30  

  2. Testing pcregrep main features  

  3. Testing pcregrep UTF-8 features  

  4. Testing pcregrep newline settings  

  5. PASS: RunGrepTest  

  6. ==================  

  7. All 5 tests passed  

  8. ==================  

  9. make[2]: Leaving directory `/usr/local/pcre-8.32'  

  10. make[1]: Leaving directory `/usr/local/pcre-8.32'  

  11. [root@localhost pcre-8.32]#  

 

5.安裝

執行make install操作:

Shell代碼  收藏代碼

  1. [root@localhost pcre-8.32]# make install  

 

make install結束后pcre編譯安裝流程就結束了。

 

 本文由用戶 haojw 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!