[GH-ISSUE #50] centos7.9 X64源码编译出错 #28

Closed
opened 2026-03-04 12:18:10 +03:00 by kerem · 8 comments
Owner

Originally created by @R1hug0 on GitHub (Jul 1, 2021).
Original GitHub issue: https://github.com/ADD-SP/ngx_waf/issues/50

如果不加参加数--with-cc-opt='-std=gnu99'会报建如下错
For gcc, you can enable the C99 standard by appending the parameter --with-cc-opt='-std=gnu99'.
如果加上参数--with-cc-opt='-std=gnu99'会报如下错误,
cc1plus: error: command line option ‘-std=gnu99’ is valid for C/ObjC but not for C++ [-Werror]

这个需要怎么解决呢

Originally created by @R1hug0 on GitHub (Jul 1, 2021). Original GitHub issue: https://github.com/ADD-SP/ngx_waf/issues/50 如果不加参加数--with-cc-opt='-std=gnu99'会报建如下错 For gcc, you can enable the C99 standard by appending the parameter --with-cc-opt='-std=gnu99'. 如果加上参数--with-cc-opt='-std=gnu99'会报如下错误, cc1plus: error: command line option ‘-std=gnu99’ is valid for C/ObjC but not for C++ [-Werror] 这个需要怎么解决呢
kerem 2026-03-04 12:18:10 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@ADD-SP commented on GitHub (Jul 1, 2021):

看起来编译器把 C 源代码文件识别为 C++ 源代码文件了。使用的编译器是 GCC 么?贴一下完整的 ./configure 参数看看。

<!-- gh-comment-id:872172090 --> @ADD-SP commented on GitHub (Jul 1, 2021): 看起来编译器把 C 源代码文件识别为 C++ 源代码文件了。使用的编译器是 GCC 么?贴一下完整的 `./configure` 参数看看。
Author
Owner

@R1hug0 commented on GitHub (Jul 2, 2021):

可能是GCC版本太低了? 版本是 gcc-4.8.5
./configure --prefix=/opt/nginx --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_secure_link_module --with-http_degradation_module --add-module=modules/ngx_http_upstream_session_sticky_module --add-module=modules/ngx_http_upstream_consistent_hash_module --add-module=./modules/mod_dubbo --add-module=./modules/ngx_multi_upstream_module --add-module=./modules/mod_config --add-module=../ngx_waf --with-mail=dynamic --with-file-aio --with-http_ssl_module --with-http_geoip_module --with-http_v2_module --with-http_realip_module --with-stream_ssl_preread_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_perl_module --with-http_stub_status_module --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt='-O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --with-cc-opt='-Werror -g -fstack-protector-strong' --with-cc-opt='-std=gnu99'

<!-- gh-comment-id:872647069 --> @R1hug0 commented on GitHub (Jul 2, 2021): 可能是GCC版本太低了? 版本是 gcc-4.8.5 ./configure --prefix=/opt/nginx --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_secure_link_module --with-http_degradation_module --add-module=modules/ngx_http_upstream_session_sticky_module --add-module=modules/ngx_http_upstream_consistent_hash_module --add-module=./modules/mod_dubbo --add-module=./modules/ngx_multi_upstream_module --add-module=./modules/mod_config --add-module=../ngx_waf --with-mail=dynamic --with-file-aio --with-http_ssl_module --with-http_geoip_module --with-http_v2_module --with-http_realip_module --with-stream_ssl_preread_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_perl_module --with-http_stub_status_module --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt='-O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --with-cc-opt='-Werror -g -fstack-protector-strong' --with-cc-opt='-std=gnu99'
Author
Owner

@ADD-SP commented on GitHub (Jul 2, 2021):

尝试把三个 --with-cc-opt 参数中的值合并到一个 --with-cc-opt 里,因为只有最后一个 --with-cc-opt 会生效。

如果不行的话尝试编辑 objs/Makefile,从 CFLAGS 删除 -Werror,然后重新编译。

<!-- gh-comment-id:872647984 --> @ADD-SP commented on GitHub (Jul 2, 2021): 尝试把三个 `--with-cc-opt` 参数中的值合并到一个 `--with-cc-opt` 里,因为只有最后一个 `--with-cc-opt` 会生效。 如果不行的话尝试编辑 `objs/Makefile`,从 `CFLAGS` 删除 `-Werror`,然后重新编译。
Author
Owner

@R1hug0 commented on GitHub (Jul 2, 2021):

试了下不行,我升级下GCC到7.0试试

<!-- gh-comment-id:872787806 --> @R1hug0 commented on GitHub (Jul 2, 2021): 试了下不行,我升级下GCC到7.0试试
Author
Owner

@ADD-SP commented on GitHub (Jul 4, 2021):

@R1hug0 解决了么?

<!-- gh-comment-id:873541779 --> @ADD-SP commented on GitHub (Jul 4, 2021): @R1hug0 解决了么?
Author
Owner

@R1hug0 commented on GitHub (Jul 5, 2021):

升级了GCC8.3,make的时候抛出下面的错误
/home/gcc/bin/gcc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Werror -g -fstack-protector-strong -I src/core -I src/event -I src/event/modules -I src/os/unix -I src/proc -I ./modules/ngx_multi_upstream_module -I/usr/include/libxml2 -I objs -I src/http -I src/http/modules -I src/http/v2 -I src/http/modules/perl -I ./modules/ngx_multi_upstream_module -I ../ngx_waf/inc -I /opt/soft/lua/uthash/include -I /usr/local/libsodium/include -I src/mail -I src/stream
-o objs/addon/src/ngx_http_waf_module_core.o
../ngx_waf/src/ngx_http_waf_module_core.c

In file included from ../ngx_waf/inc/ngx_http_waf_module_core.h:15,
from ../ngx_waf/src/ngx_http_waf_module_core.c:1:
../ngx_waf/inc/ngx_http_waf_module_check.h: In function ‘ngx_http_waf_handler_check_cc’:
../ngx_waf/inc/ngx_http_waf_module_ip_trie.h:170:43: error: array subscript 15 is above array bounds of ‘uint8_t[4]’ {aka ‘unsigned char[4]’} [-Werror=array-bounds]
if (NGX_HTTP_WAF_CHECK_BIT(u8_addr[uint8_index], 7 - (bit_index % 8)) != NGX_HTTP_WAF_TRUE) {
../ngx_waf/inc/ngx_http_waf_module_macro.h:373:50: note: in definition of macro ‘NGX_HTTP_WAF_CHECK_FLAG’
#define NGX_HTTP_WAF_CHECK_FLAG(origin, flag) (((origin) & (flag)) == (flag) ? NGX_HTTP_WAF_TRUE : NGX_HTTP_WAF_FALSE)
^~~~~~
../ngx_waf/inc/ngx_http_waf_module_ip_trie.h:170:13: note: in expansion of macro ‘NGX_HTTP_WAF_CHECK_BIT’
if (NGX_HTTP_WAF_CHECK_BIT(u8_addr[uint8_index], 7 - (bit_index % 8)) != NGX_HTTP_WAF_TRUE) {
^~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [objs/addon/src/ngx_http_waf_module_core.o] Error 1

<!-- gh-comment-id:873761310 --> @R1hug0 commented on GitHub (Jul 5, 2021): 升级了GCC8.3,make的时候抛出下面的错误 /home/gcc/bin/gcc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Werror -g -fstack-protector-strong -I src/core -I src/event -I src/event/modules -I src/os/unix -I src/proc -I ./modules/ngx_multi_upstream_module -I/usr/include/libxml2 -I objs -I src/http -I src/http/modules -I src/http/v2 -I src/http/modules/perl -I ./modules/ngx_multi_upstream_module -I ../ngx_waf/inc -I /opt/soft/lua/uthash/include -I /usr/local/libsodium/include -I src/mail -I src/stream \ -o objs/addon/src/ngx_http_waf_module_core.o \ ../ngx_waf/src/ngx_http_waf_module_core.c In file included from ../ngx_waf/inc/ngx_http_waf_module_core.h:15, from ../ngx_waf/src/ngx_http_waf_module_core.c:1: ../ngx_waf/inc/ngx_http_waf_module_check.h: In function ‘ngx_http_waf_handler_check_cc’: ../ngx_waf/inc/ngx_http_waf_module_ip_trie.h:170:43: error: array subscript 15 is above array bounds of ‘uint8_t[4]’ {aka ‘unsigned char[4]’} [-Werror=array-bounds] if (NGX_HTTP_WAF_CHECK_BIT(u8_addr[uint8_index], 7 - (bit_index % 8)) != NGX_HTTP_WAF_TRUE) { ../ngx_waf/inc/ngx_http_waf_module_macro.h:373:50: note: in definition of macro ‘NGX_HTTP_WAF_CHECK_FLAG’ #define NGX_HTTP_WAF_CHECK_FLAG(origin, flag) (((origin) & (flag)) == (flag) ? NGX_HTTP_WAF_TRUE : NGX_HTTP_WAF_FALSE) ^~~~~~ ../ngx_waf/inc/ngx_http_waf_module_ip_trie.h:170:13: note: in expansion of macro ‘NGX_HTTP_WAF_CHECK_BIT’ if (NGX_HTTP_WAF_CHECK_BIT(u8_addr[uint8_index], 7 - (bit_index % 8)) != NGX_HTTP_WAF_TRUE) { ^~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[1]: *** [objs/addon/src/ngx_http_waf_module_core.o] Error 1
Author
Owner

@ADD-SP commented on GitHub (Jul 5, 2021):

--with-cc-opt 中追加 -Wno-array-bounds

<!-- gh-comment-id:873803497 --> @ADD-SP commented on GitHub (Jul 5, 2021): 在 `--with-cc-opt` 中追加 `-Wno-array-bounds`。
Author
Owner

@R1hug0 commented on GitHub (Jul 5, 2021):

--with-cc-opt 中追加 -Wno-array-bounds

Ok, done

<!-- gh-comment-id:873940959 --> @R1hug0 commented on GitHub (Jul 5, 2021): > 在 `--with-cc-opt` 中追加 `-Wno-array-bounds`。 Ok, done
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ngx_waf#28
No description provided.