nginx源码编译时常见错误解决方法


最近在研究nginx源码,准备对源码进行调试,需要'-g'选项编译nginx,便于使用GDB调试nginx。

编译源码的过程中发现很多问题,决定进行一番梳理。

编译环境:

###Ubuntu20.04&gcc--version 9.3.0###

nginx源码版本:nginx-1.12.0

编译nginx所需要的库及版本号:

pcre-8.37

openssl-1.1.0h

zlib-1.2.11

配置命令:

./configure --prefix=/home/zyz/nginx1.12.0/   --with-http_ssl_module   --with-http_stub_status_module  --with-pcre=/home/zyz/pcre-8.37/   --with-openssl=/home/zyz/openssl-1.1.0h/    --with-zlib=/home/zyz/zlib-1.2.11/
编译命令:

make

报错:

make -f objs/Makefile

make[1]: Entering directory '/home/zyz/nginx-1.12.0'

cd ../pcre-8.37/ \

&& if [ -f Makefile ]; then make distclean; fi \

&& CC="cc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \

./configure --disable-shared 

/bin/sh -3: permission deny

解决方法:

经过一番分析发现是pcre-8.37 和openssl-1.1.0h库中的configure文件和config文件默认无执行权限,

果断进入 两个库文件夹,执行chmod 777 configure  ;   chmod 777 config

于是乎make,开始大量编译...

过了一会儿,又报了另外一个错误!

src/core/ngx_murmurhash.c: In function ‘ngx_murmur_hash2’:
src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
   37 |         h ^= data[2] << 16;
      |         ~~^~~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:38:5: note: here
   38 |     case 2:
      |     ^~~~
src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
   39 |         h ^= data[1] << 8;
      |         ~~^~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:40:5: note: here
   40 |     case 1:
      |     ^~~~
cc1: all warnings being treated as errors
make[1]: *** [objs/Makefile:482:objs/src/core/ngx_murmurhash.o] 错误 1
make[1]: 离开目录“/home/zyz/nginx-1.12.0”
make: *** [Makefile:8:build] 错误 2
解决方法:

进入objs/Makefile,打开Makefile文件将编译选项中的CFLAGS =  -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter  -werror -g中的“-werror"删除。

###-werror是将警告对待成错误(warning treated as  error)。

继续进行编译...

又报错误了。。。

如下:

src/os/unix/ngx_user.c: In function ‘ngx_libc_crypt’:
src/os/unix/ngx_user.c:36:7: error: ‘struct crypt_data’ has no member named ‘current_salt’
   36 |     cd.current_salt[0] = ~salt[0];
      |       ^
make[1]: *** [objs/Makefile:797:objs/src/os/unix/ngx_user.o] 错误 1
make[1]: 离开目录“/home/zyz/nginx-1.12.0/nginx-1.12.0”
make: *** [Makefile:8:build] 错误 2

解决方法:

经过百度发现需要进入../src/os/unix/ngx_user.c中进行源码修改。

只需要注释第36行代码即可。

/* cd.current_salt[0] = ~salt[0];*/
继续进行编译...

编译完成!

sed -e "s|%%PREFIX%%|/home/zyz/nginx1.12.0/|" \
    -e "s|%%PID_PATH%%|/home/zyz/nginx1.12.0//logs/nginx.pid|" \
    -e "s|%%CONF_PATH%%|/home/zyz/nginx1.12.0//conf/nginx.conf|" \
    -e "s|%%ERROR_LOG_PATH%%|/home/zyz/nginx1.12.0//logs/error.log|" \
    < man/nginx.8 > objs/nginx.8
make[1]: 离开目录“/home/zyz/nginx-1.12.0”
安装

make install

root@zyz:/home/zyz/nginx-1.12.0# make install
make -f objs/Makefile install
make[1]: 进入目录“/home/zyz/nginx-1.12.0”
test -d '/home/zyz/nginx1.12.0/' || mkdir -p '/home/zyz/nginx1.12.0/'
test -d '/home/zyz/nginx1.12.0//sbin' \
    || mkdir -p '/home/zyz/nginx1.12.0//sbin'
test ! -f '/home/zyz/nginx1.12.0//sbin/nginx' \
    || mv '/home/zyz/nginx1.12.0//sbin/nginx' \
        '/home/zyz/nginx1.12.0//sbin/nginx.old'
cp objs/nginx '/home/zyz/nginx1.12.0//sbin/nginx'
test -d '/home/zyz/nginx1.12.0//conf' \
    || mkdir -p '/home/zyz/nginx1.12.0//conf'
cp conf/koi-win '/home/zyz/nginx1.12.0//conf'
cp conf/koi-utf '/home/zyz/nginx1.12.0//conf'
cp conf/win-utf '/home/zyz/nginx1.12.0//conf'
test -f '/home/zyz/nginx1.12.0//conf/mime.types' \
    || cp conf/mime.types '/home/zyz/nginx1.12.0//conf'
cp conf/mime.types '/home/zyz/nginx1.12.0//conf/mime.types.default'
test -f '/home/zyz/nginx1.12.0//conf/fastcgi_params' \
    || cp conf/fastcgi_params '/home/zyz/nginx1.12.0//conf'
cp conf/fastcgi_params \
    '/home/zyz/nginx1.12.0//conf/fastcgi_params.default'
test -f '/home/zyz/nginx1.12.0//conf/fastcgi.conf' \
    || cp conf/fastcgi.conf '/home/zyz/nginx1.12.0//conf'
cp conf/fastcgi.conf '/home/zyz/nginx1.12.0//conf/fastcgi.conf.default'
test -f '/home/zyz/nginx1.12.0//conf/uwsgi_params' \
    || cp conf/uwsgi_params '/home/zyz/nginx1.12.0//conf'
cp conf/uwsgi_params \
    '/home/zyz/nginx1.12.0//conf/uwsgi_params.default'
test -f '/home/zyz/nginx1.12.0//conf/scgi_params' \
    || cp conf/scgi_params '/home/zyz/nginx1.12.0//conf'
cp conf/scgi_params \
    '/home/zyz/nginx1.12.0//conf/scgi_params.default'
test -f '/home/zyz/nginx1.12.0//conf/nginx.conf' \
    || cp conf/nginx.conf '/home/zyz/nginx1.12.0//conf/nginx.conf'
cp conf/nginx.conf '/home/zyz/nginx1.12.0//conf/nginx.conf.default'
test -d '/home/zyz/nginx1.12.0//logs' \
    || mkdir -p '/home/zyz/nginx1.12.0//logs'
test -d '/home/zyz/nginx1.12.0//logs' \
    || mkdir -p '/home/zyz/nginx1.12.0//logs'
test -d '/home/zyz/nginx1.12.0//html' \
    || cp -R html '/home/zyz/nginx1.12.0/'
test -d '/home/zyz/nginx1.12.0//logs' \
    || mkdir -p '/home/zyz/nginx1.12.0//logs'
make[1]: 离开目录“/home/zyz/nginx-1.12.0”

生成nginx可执行文件

 执行./nginx

 好了,nginx源码的编译及执行就介绍完了。下篇介绍nginx的调试,哈哈!!!

2020-11-28 11:27:33


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM