CentOS安装openresty或者verynginx时:undefined reference to `pcre_free_study'

本文记录了在CentOS上安装OpenResty 1.11.2.5及VeryNginx时遇到的pcre相关错误,并提供了解决方案,通过更新pcre版本并指定路径配置解决了编译错误。

一、openresty问题复现:centos安装openresty-1.11.2.5,./configure后make时报错:

https://blog.iaiot.com/openresty.html

objs/addon/src/ngx_http_lua_regex.o: In function `ngx_http_lua_regex_free_study_data':
/home/openresty-1.11.2.5/build/nginx-1.11.2/../ngx_lua-0.10.10/src/ngx_http_lua_regex.c:2015: undefined reference to `pcre_free_study'
objs/addon/src/ngx_http_lua_regex.o: In function `ngx_http_lua_ffi_destroy_regex':
/home/openresty-1.11.2.5/build/nginx-1.11.2/../ngx_lua-0.10.10/src/ngx_http_lua_regex.c:2413: undefined reference to `pcre_free_study'
objs/addon/src/ngx_http_lua_regex.o: In function `ngx_http_lua_ffi_compile_regex':
/home/openresty-1.11.2.5/build/nginx-1.11.2/../ngx_lua-0.10.10/src/ngx_http_lua_regex.c:2268: undefined reference to `pcre_assign_jit_stack'
objs/addon/src/ngx_http_lua_regex.o: In function `ngx_http_lua_ngx_re_gmatch':
/home/openresty-1.11.2.5/build/nginx-1.11.2/../ngx_lua-0.10.10/src/ngx_http_lua_regex.c:828: undefined reference to `pcre_assign_jit_stack'
objs/addon/src/ngx_http_lua_regex.o: In function `ngx_http_lua_ffi_set_jit_stack_size':
/home/openresty-1.11.2.5/build/nginx-1.11.2/../ngx_lua-0.10.10/src/ngx_http_lua_regex.c:1950: undefined reference to `pcre_jit_stack_free'
/home/openresty-1.11.2.5/build/nginx-1.11.2/../ngx_lua-0.10.10/src/ngx_http_lua_regex.c:1957: undefined reference to `pcre_jit_stack_alloc'
objs/addon/src/ngx_http_lua_regex.o: In function `ngx_http_lua_ngx_re_match_helper':
/home/openresty-1.11.2.5/build/nginx-1.11.2/../ngx_lua-0.10.10/src/ngx_http_lua_regex.c:362: undefined reference to `pcre_assign_jit_stack'
collect2: ld returned 1 exit status
gmake[2]: *** [objs/nginx] Error 1
gmake[2]: Leaving directory `/home/openresty-1.11.2.5/build/nginx-1.11.2'
gmake[1]: *** [build] Error 2
gmake[1]: Leaving directory `/home/openresty-1.11.2.5/build/nginx-1.11.2'
gmake: *** [all] Error 2

很明显是pcre的问题,Google说是pcre版本问题;

解决办法:

1.下载新版本pcre,我下载的是pcre-8.38,解压,不需要安装;我服务器原版本是pcre-7.8.7

2.然后openresty目录下执行./configure时指定PCRE库的源码路径--with-pcre=/home/pcre-8.38

例:./configure --with-pcre=/home/pcre-8.38 (已省略其他编译参数,需要自行添加)

然后make,make install即可

 

二、安装verynginx时报同样错误

复现:python install.py install安装verynginx时,报同样错误;

解决:VeryNginx目录下install.py中大约51行处找到exec_sys_cmd( './configure --prefix=/opt/verynginx/openresty --user=nginx --group=nginx --with-http_v2_module --with-http_sub_module --with-http_stub_status_module --with-luajit ' )

后面同样加上--with-pcre=/home/pcre-8.38

即:exec_sys_cmd( './configure --prefix=/opt/verynginx/openresty --user=nginx --group=nginx --with-http_v2_module --with-http_sub_module --with-http_stub_status_module --with-luajit --with-pcre=/home/pcre-8.38' )

然后再执行python install.py install即可

 

 

参考地址:https://groups.google.com/forum/#!msg/openresty/o4CKvsp3Gio/9kiGJVSECgAJ

                 https://github.com/openresty/lua-nginx-module/issues/781

                 http://www.runoob.com/w3cnote/nginx-install-and-config.html

<think>我们正在解决OpenResty编译出现的错误:undefined reference to `SSL_get_client_random` 根据引用[1]中的错误信息,类似的问题(undefined reference to `EC_KEY_new_by_curve_name'等)通常是由于OpenSSL库链接问题导致的。 而当前错误`undefined reference to SSL_get_client_random`同样可能是由于OpenSSL版本不兼容或链接不正确引起的。 解决方案思路: 1. 确认系统中安装了正确版本的OpenSSL(OpenResty所需的版本,通常需要较新的版本,因为`SSL_get_client_random`函数是在OpenSSL 1.1.1及以上版本中引入的) 2. 在编译OpenResty,确保正确指定OpenSSL的路径,以便链接到正确的OpenSSL库。 具体步骤: 步骤1:检查OpenSSL版本 在终端执行: ```bash openssl version ``` 如果版本低于1.1.1,则需要升级OpenSSL(因为`SSL_get_client_random`是在1.1.1版本中引入的)。 步骤2:升级OpenSSL(如果版本过低) 可以参考我们之前提供的OpenSSL升级流程,但这里我们更关注如何让OpenResty链接到新版本的OpenSSL。 步骤3:重新编译OpenResty,并指定OpenSSL路径 在编译OpenResty,通过`--with-openssl`选项指定新安装的OpenSSL源码目录(注意:是源码目录,不是安装目录,因为OpenResty需要重新编译OpenSSL?实际上,OpenResty的编译脚本会使用该目录下的OpenSSL源码进行编译,但也可以使用已安装的库,不过为了确保兼容性,通常使用源码)。 例如,假设我们下载的OpenSSL源码在`/usr/local/src/openssl-1.1.1w`(这里以1.1.1w为例,实际请使用最新稳定版),则编译OpenResty: ```bash ./configure --with-openssl=/usr/local/src/openssl-1.1.1w [其他选项] ``` 注意:OpenResty的编译脚本会自动使用该目录下的OpenSSL源码进行编译并链接。 如果已经安装了新版本的OpenSSL,也可以尝试使用`--with-openssl=/usr/local/openssl`(安装目录)来指定,但可能不如使用源码可靠。 步骤4:清除之前的编译缓存并重新编译 在重新配置之前,确保先执行`make clean`(如果之前已经编译过)。 完整步骤示例: 1. 下载并解压OpenResty源码,进入源码目录。 2. 下载OpenSSL源码(如果需要升级)并解压到某个目录,例如`/usr/local/src/openssl-1.1.1w`。 3. 配置: ```bash ./configure --with-openssl=/usr/local/src/openssl-1.1.1w \ --with-http_ssl_module \ --with-stream_ssl_module \ [其他你需要的模块] ``` 4. 编译并安装: ```bash make sudo make install ``` 步骤5:如果问题依旧,可能需要检查是否链接了正确的库。在编译过程中,可以查看编译日志,确认链接的OpenSSL库是否正确。 另外,根据引用[2]中的提示,如果系统没有安装openssl-devel,也可能导致问题。所以确保已经安装了openssl-devel(对于新安装的OpenSSL,可能需要通过源码安装,并确保开发文件(头文件和库)在标准路径或者通过环境变量指定)。 如果系统中有多个OpenSSL版本,可能需要调整库的搜索路径(使用ldconfig)或者设置环境变量: ```bash export LD_LIBRARY_PATH=/usr/local/openssl/lib:$LD_LIBRARY_PATH ``` 步骤6:验证 编译安装完成后,运行OpenRestynginx,检查是否正常加载,以及SSL功能是否正常。 如果上述步骤不能解决问题,可能需要查看具体的错误信息,并检查OpenResty版本是否支持所使用的OpenSSL版本。 注意:OpenResty的某些版本可能需要特定版本的OpenSSL,请查阅OpenResty的官方文档或发布说明。 生成的相关问题: 1. 如何查看当前系统安装的OpenSSL版本? 2. 如何让系统同存在多个OpenSSL版本? 3. OpenResty编译如何指定其他库的路径? 4. 如何解决动态库链接错误? 下面我们按照步骤详细说明。</think>### OpenResty 编译错误 `undefined reference to SSL_get_client_random` 解决方案 #### 🔍 问题原因分析 该错误表示 OpenResty 在编译无法链接 OpenSSL 的 `SSL_get_client_random` 函数,通常由以下原因导致: 1. **OpenSSL 版本不兼容**:`SSL_get_client_random` 是 OpenSSL 1.1.1+ 新增的 API,旧版本不存在此函数[^1] 2. **链接库路径错误**:编译未正确指向新版 OpenSSL 库位置 3. **头文件不匹配**:编译使用的 OpenSSL 头文件与链接库版本不一致 4. **ABI 兼容性问题**:OpenResty 版本与 OpenSSL 3.0 存在兼容性问题 #### ✅ 完整解决步骤 ##### 1. 确认 OpenSSL 版本 ```bash # 检查当前链接的 OpenSSL 版本 openssl version # 检查动态库路径 ldd $(which openssl) | grep ssl ``` * 要求:**必须使用 OpenSSL 1.1.1 或更高版本** ##### 2. 安装新版 OpenSSL 开发包 ```bash # Ubuntu/Debian sudo apt update sudo apt install libssl-dev -y # CentOS/RHEL sudo yum install openssl-devel -y ``` ##### 3. 编译 OpenResty 指定 OpenSSL 路径 ```bash # 关键配置参数(根据实际路径调整) ./configure \ --with-openssl=/usr/local/openssl \ # 指向新版OpenSSL安装目录 --with-openssl-opt="shared" \ # 确保生成动态库 --with-http_ssl_module \ # 启用SSL模块 --with-stream_ssl_module # 启用Stream SSL模块 # 完整示例(假设OpenSSL安装在/usr/local/openssl) ./configure \ --prefix=/usr/local/openresty \ --with-openssl=/usr/local/openssl \ --with-openssl-opt="shared" \ --with-http_ssl_module \ --with-stream_ssl_module \ --with-pcre-jit \ --with-stream \ --with-stream_ssl_preread_module ``` ##### 4. 设置库链接路径 ```bash # 临生效(编译期间) export LD_LIBRARY_PATH=/usr/local/openssl/lib:$LD_LIBRARY_PATH # 永久生效 sudo sh -c "echo '/usr/local/openssl/lib' >> /etc/ld.so.conf" sudo ldconfig ``` ##### 5. 验证链接库版本 编译前检查 `objs/autoconf.err` 文件,确认: ```log checking for OpenSSL library ... found checking for OpenSSL version ... 101010af (OpenSSL 1.1.1) ``` ##### 6. 完整编译安装 ```bash # 清除旧编译缓存 make clean # 编译并安装 make -j$(nproc) sudo make install ``` #### ⚠️ 特殊情况处理 **场景1:系统存在多版本 OpenSSL** ```bash # 强制指定链接路径 ./configure ... \ LDFLAGS="-L/usr/local/openssl/lib" \ CPPFLAGS="-I/usr/local/openssl/include" ``` **场景2:需要降级 OpenSSL** ```bash # 安装 OpenSSL 1.1.1 cd /usr/local/src wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz tar -zxvf openssl-1.1.1w.tar.gz cd openssl-1.1.1w ./config --prefix=/usr/local/openssl shared make && sudo make install ``` **场景3:OpenResty 版本过旧** ```bash # 升级到支持 OpenSSL 3.0 的版本 git clone https://github.com/openresty/openresty.git cd openresty ./configure --prefix=/usr/local/openresty ... ``` #### ✅ 验证安装 ```bash # 检查链接库 ldd /usr/local/openresty/nginx/sbin/nginx | grep ssl # 测试SSL函数 /usr/local/openresty/bin/resty -e 'print(require("resty.openssl.version").version)' ``` #### 📌 预防措施 1. **编译前清理**:始终先运行 `make clean` 2. **环境隔离**:使用 `docker buildx` 构建确定性的编译环境[^3] 3. **版本匹配**:参考 [OpenResty 官方兼容性矩阵](https://openresty.org/en/installation.html) 4. **日志分析**:检查 `build/nginx-*/objs/autoconf.err` 获取详细错误信息 ```mermaid graph TD A[编译错误] --> B{检查OpenSSL版本} B -->|≥1.1.1| C[指定路径重新编译] B -->|<1.1.1| D[升级OpenSSL] C --> E[设置LD_LIBRARY_PATH] E --> F[验证链接] D --> C ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值