最后更新于

ngx_http_lua_module.so: undefined symbol: pcre_dfa_exec问题解决


最近在编译nginx使用ngx_http_lua_module遇到错误:ngx_http_lua_module.so: undefined symbol: pcre_dfa_exec

❌ 问题原因

ngx_http_lua_module使用了PCRE库,但系统中缺少PCRE库或者编译时没有正确链接PCRE库。

✅ 解决办法

📦 安装PCRE库

下载地址:

安装步骤:

tar zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure
make
make install

🔧 添加编译参数

在编译nginx的时候,加上以下参数:

--with-ld-opt="-lpcre -Wl,-rpath,/usr/local/lib"

关键是 -lpcre 参数,它告诉编译器链接PCRE库。

📝 完整编译示例

./configure \
    --with-http_lua_module \
    --with-ld-opt="-lpcre -Wl,-rpath,/usr/local/lib" \
    --other-options...

make
make install

💡 其他注意事项

  • 确保PCRE库已正确安装在系统中
  • 如果使用包管理器安装,确保同时安装了开发包(如pcre-devel)
  • 检查库文件路径是否正确,必要时调整-Wl,-rpath参数