编译选项的使用
1.禁止隐式声明
-Werror=implicit-function-declaration 编译选项中加了这个,隐式声明不过,报error而不是warning了
eg: test.c int main(int argc, char *argv[]) { char *pstr = "hello nihao"; printf("l pstr=%s\n", pstr); } [ubuntu @tmp]$ gcc test.c -o pp test.c: In function ‘main’: test.c:5:2: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default] printf("l pstr=%s\n", pstr); [ubuntu @tmp]$ gcc test.c -Werror=implicit-function-declaration -o pp test.c: In function ‘main’: test.c:5:2: error: implicit declaration of function ‘printf’ [-Werror=implicit-function-declaration] printf("l pstr=%s\n", pstr); ^ test.c:5:2: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default] cc1: some warnings being treated as errors
2. __unused 加载参数后面表示参数不使用,就不会报参数没有使用的警告了
int main(int argc __unused, char *argv[] __unused) { return 0; }
3. 屏蔽报错
cc_defaults { name: "test_flags", cflags: [ "-Wno-unused-variable", //让这个警告不报成Error "-Wno-unused-parameter", "-Wno-address-of-packed-member" ], shared_libs: ["liblog"], }
将 "-Wunused-parameter" 形式修改为 "Wno-unused-parameter" 形式以取消警告导致中断编译,将"-W"修改为"Wno-",-Wunused-*之类所有问题可以套这个万能公式。
4. C++中若不想让"Werror"对没有使用后的函数报错,可以使用 [[maybe_unused]] static String16 get_interface_name() 进行修饰。
参考:
https://blog.csdn.net/u010164190/article/details/131525733
posted on 2018-05-27 15:42 Hello-World3 阅读(391) 评论(0) 编辑 收藏 举报