Linux下编译安装PCRE库

时间:2023-03-09 03:58:52
Linux下编译安装PCRE库

备注:如果没有root权限,使用 --prefix 指定安装路径

./configure --prefix=/home/work/tools/pcre-8.xx

======================================================

最近在学习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.把安装包上传到服务器,然后解压

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

解压之后在当前目录下生成了一个文件夹:pcre-8.32

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

3.配置

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

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

  1. pcre-8.32 configuration summary:
  2. Install prefix .................. : /usr/local
  3. C preprocessor .................. : gcc -E
  4. C compiler ...................... : gcc
  5. C++ preprocessor ................ : g++ -E
  6. C++ compiler .................... : g++
  7. Linker .......................... : /usr/bin/ld
  8. C preprocessor flags ............ :
  9. C compiler flags ................ : -O2 -fvisibility=hidden
  10. C++ compiler flags .............. : -O2 -fvisibility=hidden -fvisibility-inlines-hidden
  11. Linker flags .................... :
  12. Extra libraries ................. :
  13. Build 8 bit pcre library ........ : yes
  14. Build 16 bit pcre library ....... : no
  15. Build 32 bit pcre library ....... : no
  16. Build C++ library ............... : yes
  17. Enable JIT compiling support .... : no
  18. Enable UTF-8/16/32 support ...... : no
  19. Unicode properties .............. : no
  20. Newline char/sequence ........... : lf
  21. \R matches only ANYCRLF ......... : no
  22. EBCDIC coding ................... : no
  23. EBCDIC code for NL .............. : n/a
  24. Rebuild char tables ............. : no
  25. Use stack recursion ............. : yes
  26. POSIX mem threshold ............. : 10
  27. Internal link size .............. : 2
  28. Match limit ..................... : 10000000
  29. Match limit recursion ........... : MATCH_LIMIT
  30. Build shared libs ............... : yes
  31. Build static libs ............... : yes
  32. Use JIT in pcregrep ............. : no
  33. Buffer size for pcregrep ........ : 20480
  34. Link pcregrep with libz ......... : no
  35. Link pcregrep with libbz2 ....... : no
  36. Link pcretest with libedit ...... : no
  37. Link pcretest with libreadline .. : no
  38. Valgrind support ................ : no
  39. Code coverage ................... : no

4.编译

执行make操作:

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

编译完后可以执行make check进行测试(这一步非必须)

  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结果中有一句:

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

这是因为在前面步骤中执行./configuration配置时没有加上对utf-8的支持

如果要加上对utf-8的支持可以在./configuration时加上参数:

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

配置完后再重新make

make完后再次执行make check结果如下:

  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操作:

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

make install结束后pcre编译安装流程就结束了。