背景
nginx需要使用到fastdfs-nginx-module,我把它添加进nginx中,成功之后,我执行nginx中的objs/Makefile文件。
假如说已经在nginx源码目录中,我会执行如下命令:
make objs/Makefile
错误
编译到快结束时会出现这些错误:
cc1: all warnings being treated as errors make[1]: * [objs/Makefile:1335: objs/addon/src/ngx_http_fastdfs_module.o] Error 1 make[1]: Leaving directory '/home/ubuntu/mypacket/nginx-1.16.1' make: * [Makefile:8: build] Error 2
编译过程中的错误如下: error: ‘%s’ directive output may be truncated writing up to 510 bytes into a region of size between 111 and 127 [-Werror=format-truncation=] 902 | file_id_without_group = uri + 1; //skip / | ~~~~~~~ 903 | snprintf(file_id, sizeof(file_id), "%s/%s", \ | ^~
error: ‘%s’ directive output may be truncated writing up to 510 bytes into a region of size 128 [-Werror=format-truncation=] 857 | snprintf(file_id, sizeof(file_id), "%s", uri + 1); |
原因
Makefile文件中,设置的编译等级比较高,使用-werror选项,导致如果出现任何警告都将视为错误,所以就会导致编译失败。
解决方法
在Makefile中,将-werror删除。重新执行:
make objs/Makefile
就可以成功。