Linux系统下安装PCRE及配置共享库教程

PCRE是一个用C语言编写的正则表达式函数库,比较轻量级,PCRE十分易用,同时功能也很强大,本文我们来看看在Linux如何安装PCRE及及配置共享库.

PCRE(Perl Compatible Regular Expressions)是一个轻量级的Perl函数库,包括 perl 兼容的正则表达式库,它比Boost之类的正则表达式库小得多,PCRE十分易用,同时功能也很强大,性能超过了POSIX正则表达式库和一些经典的正则表达式库.

安装PCRE:

1.PCRE目前最新版本为8.36,可以点这里进行下载.

2.使用tar -zxvf pcre-8.36.tar.gz进行解压.

3.运行 chmod -R 777 /pcre-8.36 对当前文件夹授予全部读写权限.

4.切换到/pcre-8.36目录下,运行 ./configure 进行pcre初始化配置,会在控制台打印出一大堆的输出信息.

5.执行make操作,进行编译.

  1. [root@server06 pcre-8.36]# make
  2. rm -f pcre_chartables.c
  3. ln -s ./pcre_chartables.c.dist pcre_chartables.c
  4. make all-am
  5. make[1]: Entering directory `/opt/nginx/pcre-8.36'
  6. CC libpcre_la-pcre_byte_order.lo
  7. CC libpcre_la-pcre_compile.lo
  8. CC libpcre_la-pcre_config.lo
  9. CC libpcre_la-pcre_dfa_exec.lo
  10. CC libpcre_la-pcre_exec.lo
  11. CC libpcre_la-pcre_fullinfo.lo
  12. CC libpcre_la-pcre_get.lo
  13. CC libpcre_la-pcre_globals.lo
  14. CC libpcre_la-pcre_jit_compile.lo
  15. CC libpcre_la-pcre_maketables.lo
  16. CC libpcre_la-pcre_newline.lo
  17. CC libpcre_la-pcre_ord2utf8.lo
  18. CC libpcre_la-pcre_refcount.lo
  19. CC libpcre_la-pcre_string_utils.lo
  20. CC libpcre_la-pcre_study.lo
  21. CC libpcre_la-pcre_tables.lo
  22. CC libpcre_la-pcre_ucd.lo
  23. CC libpcre_la-pcre_valid_utf8.lo
  24. CC libpcre_la-pcre_version.lo
  25. CC libpcre_la-pcre_xclass.lo
  26. CC libpcre_la-pcre_chartables.lo
  27. CCLD libpcre.la
  28. CC libpcreposix_la-pcreposix.lo
  29. CCLD libpcreposix.la
  30. CXX libpcrecpp_la-pcrecpp.lo
  31. CXX libpcrecpp_la-pcre_scanner.lo
  32. CXX libpcrecpp_la-pcre_stringpiece.lo
  33. CXXLD libpcrecpp.la
  34. CC pcretest-pcretest.o
  35. CC pcretest-pcre_printint.o
  36. CCLD pcretest //phpfensi.com
  37. CC pcregrep-pcregrep.o
  38. CCLD pcregrep
  39. CXX pcrecpp_unittest-pcrecpp_unittest.o
  40. CXXLD pcrecpp_unittest
  41. CXX pcre_scanner_unittest-pcre_scanner_unittest.o
  42. CXXLD pcre_scanner_unittest
  43. CXX pcre_stringpiece_unittest-pcre_stringpiece_unittest.o
  44. CXXLD pcre_stringpiece_unittest
  45. make[1]: Leaving directory `/opt/nginx/pcre-8.36'

6.运行 [root@server06 pcre-8.36]# make install,进行安装,至此PCRE安装完成.

[root@server06 pcre-8.36]# make install

PCRE配置共享库.

问题信息:./nginx:error while loading shared libraries:libpcre.so.1: cannot open shared object file: No such file or directory

问题原因:没有安装PCRE库,或安装了PCRE库而没有配置PCRE共享库.

解决方案:配置PCRE共享库.

1.查找pcre库的位置.

  1. [root@server06 ~]# cd /lib
  2. [root@server06 lib]# find / -type f -name *libpcre.so.*
  3. /lib64/libpcre.so.0.0.1
  4. /usr/local/lib/libpcre.so.1.2.4
  5. /opt/nginx/pcre-8.36/.libs/libpcre.so.1.2.4

2.将PCRE库进行软连接.

RedHat 64位机器读取的pcre文件为/lib64/libpcre.so.0.0.1文件.

  1. [root@server06 ~]# ln -s /usr/local/lib/libpcre.so.1 /lib64/
  2. [root@server06 ~]# cd /usr/local/nginx/sbin/
  3. [root@server06 sbin]# ./nginx

如32位机器操作方式类型,可能软连接的地址为:

ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1。