Tengine 編譯出錯----can not be used when making a PIE object; recompile with -fPIC


 1 root@data-server /m/o/tengine# ./configure --prefix=/usr/local/nginx --with-pcre --with-stream  --with-http_perl_module \
 2                                --with-http_mp4_module \
 3                                --with-http_flv_module \
 4                                --with-http_gunzip_module \
 5                                --with-http_ssl_module \
 6                                --with-http_realip_module \
 7                                --with-file-aio \
 8                                --group=nginx \
 9                                --user=USER \
10                                --conf-path=/etc/nginx/nginx.conf \
11                                --sbin-path=/usr/local/sbin/nginx  && make && make install
12 ...
13 /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
14 /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
15 /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
16 /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
17 /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
18 /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
19 /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
20 /usr/bin/ld: 最后的鏈結失敗: 輸出不可表示的節
21 collect2: 錯誤:ld 返回 1
22 make[1]: *** [objs/Makefile:290:objs/nginx] 錯誤 1
23 make[1]: 離開目錄"/mdata/opt/tengine"
24 make: *** [Makefile:8:build] 錯誤 2
View Code

在編譯nginx的時候遇見上面的錯誤,各種折騰,都沒有解決,最終終於按照同事的思路,找到解決方案了:

  解決辦法:

修改編譯完的文件:objs/Makefile

在所有包含CFLAGS參數的后面添加 -fPIC,最終改完結果如下:

1 root@data-server /m/o/tengine# head objs/Makefile | grep CFLAGS
2 CFLAGS =  -fPIC -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g
3 NGX_PERL_CFLAGS = -fPIC -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib64/perl5/CORE
4 NGX_PM_CFLAGS = -fPIC -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib64/perl5/CORE
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM