c++ - 如何禁用来自 VS-Code GCC 编译器的警告?(不使用#pragma)
问题描述
我正在使用 C/C++ 智能感知 [gcc-arm] 开发 VS-Code。当我编译时,VS-Code 向我显示了数百个这样的警告:
Conversion from 'int' to u16_t{aka 'short unsigned int'} may change value [-Wconversion]
我不希望 VSCode 向我显示这些警告。但我无权编辑源代码。那么,有什么方法可以通过向 c_cpp_properties.json 文件添加一些参数来禁用这些警告?
解决方案
在这里参考我自己的参考文档,如果您可以访问构建标志,则可以-Wno-conversion
在编译时传入以禁用此警告。
从我的文件:
其他 C 和 C++ 构建说明(例如:w/
gcc
或clang
编译器):
用于
-Wwarning-name
打开构建警告“警告名称”,并-Wno-warning-name
关闭构建警告“警告名称”。-W
打开警告,-Wno-
关闭警告。以下是 gcc 对此的看法(来源:https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html;强调添加):您可以请求许多带有以 开头的选项的特定警告
-W
,例如-Wimplicit
请求对隐式声明的警告。这些特定的警告选项中的每一个也都有一个否定形式,开始-Wno-
关闭警告;例如,-Wno-implicit
. 本手册仅列出了两种形式中的一种,以非默认形式为准。
关于 Visual Studio Code,我不使用该 IDE,但该c_cpp_properties.json
文件似乎无法设置构建标志:https ://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference 。
tasks.json
但是,该文件确实: https://code.visualstudio.com/docs/cpp/config-linux#_build-helloworldcpp。
这是他们的例子:
{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "g++ build active file", "command": "/usr/bin/g++", "args": ["-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"], "options": { "cwd": "/usr/bin" }, "problemMatcher": ["$gcc"], "group": { "kind": "build", "isDefault": true } } ] }
因此,看起来您可以添加-Wno-conversion
到args
JSON 文件中的列表中,如下所示:
"args": [
"-Wno-conversion",
"-g",
"${file}",
"-o", "${fileDirname}/${fileBasenameNoExtension}"
],
也可以看看:
推荐阅读
- java - Android 手势:Scroll vs Fling
- java - Java - 从剪贴板检索 XML (Excel) 电子表格
- xmpp - 在 xmpp ejabberd 服务器上使用 Tsung 进行负载测试是否会创建原始数据?
- python - Numpy 错误地计算特征值。该怎么办?
- javascript - 无法在css中选择具有宽度属性的文本
- reactjs - Gatsby 生产版本与本地版本不同
- javascript - 为什么 textPath 中 startOffset 的百分比值在不同的窗口大小中没有响应/一致?
- mysql - 如何在 WHERE 子句中重用 SQL SELECT 语句中的变量
- python - 带有 cs 和 AIOHTTP 的 Discord.py Meme 命令
- javascript - 本地/全局范围和 NAN 问题