编译选项的使用
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 阅读(424) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!