首页 > 其他 > 详细

Nginx编译报错解决方法

时间:2021-03-11 17:39:59      阅读:23      评论:0      收藏:0      [点我收藏+]
操作系统:阿里云ECS CentOS Linux release 8.1.1911 (Core)
Nginx版本:nginx-1.18.0

安装步骤:
1、创建nginx用户
useradd -s /sbin/nologin -r nginx
2、安装依赖
yum -y install gcc pcre-devel openssl-devel zlib-devel perl-ExtUtils-Embed
3、编译
./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_perl_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
4、make 报错
报错信息如下:

/usr/bin/ld: objs/src/stream/ngx_stream_write_filter_module.o: relocation R_X86_64_32S against `.text‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_ssl_module.o: relocation R_X86_64_32 against `.rodata.str1.1‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_realip_module.o: relocation R_X86_64_32S against `.text‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_limit_conn_module.o: relocation R_X86_64_32S against `.rodata‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_access_module.o: relocation R_X86_64_32 against `.rodata.str1.1‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_geo_module.o: relocation R_X86_64_32 against `.data‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_map_module.o: relocation R_X86_64_32 against `.rodata.str1.1‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_split_clients_module.o: relocation R_X86_64_32 against `.rodata.str1.1‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_return_module.o: relocation R_X86_64_32 against `.rodata.str1.1‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_upstream_hash_module.o: relocation R_X86_64_32 against `.rodata.str1.8‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_upstream_least_conn_module.o: relocation R_X86_64_32 against `.rodata.str1.8‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_upstream_random_module.o: relocation R_X86_64_32 against `.rodata.str1.8‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: objs/src/stream/ngx_stream_upstream_zone_module.o: relocation R_X86_64_32 against symbol `ngx_stream_upstream_module‘ can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[1]: *** [objs/Makefile:289: objs/nginx] Error 1
make[1]: Leaving directory ‘/usr/local/src/nginx-1.18.0‘
make: *** [Makefile:8: build] Error 2

经过网上查询,终于解决问题:
解决办法:
cd /usr/local/src/nginx-1.18.0/objs
vim Makefile
在CFLAGS后面加上-fPIC,如下:
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -fPIC

保存后重新编译,成功!

Nginx编译报错解决方法

原文:https://blog.51cto.com/7300015/2655589

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!