You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Ubuntu 20.04树莓派4上编译ngx_brotli动态模块报错求助

在树莓派4 Ubuntu Server 20.04上编译Nginx Brotli动态模块报错解决办法

问题场景

尝试在树莓派4的Ubuntu Server 20.04系统上编译Nginx的Brotli动态模块,测试master和RC1版本均出现链接错误,报错信息如下:

sudo make modules
make -f objs/Makefile modules
make[1]: Entering directory '/usr/local/src/nginx-1.25.4'
cc -c -fPIC -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -Wno-deprecated-declarations -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I /usr/local/src/ngx_brotli/deps/brotli/c/include -I objs -I src/http -I src/http/modules \
    -o objs/addon/filter/ngx_http_brotli_filter_module.o \
    /usr/local/src/ngx_brotli/filter/ngx_http_brotli_filter_module.c
cc -c -fPIC -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -Wno-deprecated-declarations -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I /usr/local/src/ngx_brotli/deps/brotli/c/include -I objs -I src/http -I src/http/modules \
    -o objs/ngx_http_brotli_filter_module_modules.o \
    objs/ngx_http_brotli_filter_module_modules.c
cc -o objs/ngx_http_brotli_filter_module.so \
objs/addon/filter/ngx_http_brotli_filter_module.o \
objs/ngx_http_brotli_filter_module_modules.o \
-L/usr/local/src/ngx_brotli/deps/brotli/c/../out -lbrotlienc -lbrotlicommon -lm \
-shared
/usr/bin/ld: cannot find -lbrotlienc
/usr/bin/ld: cannot find -lbrotlicommon
collect2: error: ld returned 1 exit status
make[1]: *** [objs/Makefile:1219: objs/ngx_http_brotli_filter_module.so] Error 1
make[1]: Leaving directory '/usr/local/src/nginx-1.25.4'
make: *** [Makefile:16: modules] Error 2

解决步骤

1. 编译Brotli依赖库

报错核心是链接器找不到Brotli的库文件,需先手动编译ngx_brotli自带的Brotli依赖:

# 进入Brotli依赖目录
cd /usr/local/src/ngx_brotli/deps/brotli
# 创建编译输出目录并执行编译
mkdir -p out && cd out
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF
make
  • -DBUILD_SHARED_LIBS=OFF 生成静态库,避免后续动态库路径适配问题;树莓派ARM架构会自动适配,无需额外指定。

2. 重新配置Nginx编译参数

回到Nginx源码目录,重新执行configure命令,明确指定Brotli库的路径:

cd /usr/local/src/nginx-1.25.4
./configure --add-dynamic-module=/usr/local/src/ngx_brotli \
--with-ld-opt="-L/usr/local/src/ngx_brotli/deps/brotli/out/lib"
  • --with-ld-opt 用于告知链接器Brotli库的具体路径,确保和之前编译的输出目录一致。

3. 重新编译模块

执行模块编译命令:

make modules

此时链接器可正确找到libbrotlienc.a和libbrotlicommon.a,编译即可完成。

4. 安装并启用模块(可选)

  • 将编译好的模块安装到Nginx默认模块目录:
    sudo make install
    
  • 编辑nginx.conf,在文件开头添加模块加载指令:
    load_module modules/ngx_http_brotli_filter_module.so;
    load_module modules/ngx_http_brotli_static_module.so;
    
  • 重启Nginx使配置生效:
    sudo systemctl restart nginx
    

前置依赖检查

如果编译中出现其他错误,先确保安装了必要的编译工具:

sudo apt update && sudo apt install build-essential cmake libpcre3-dev zlib1g-dev

内容的提问来源于stack exchange,提问作者DanRan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 10:33:16