参考我自己的参考文档在这里 https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world#additional-c-and-c-build-notes-ex-wgcc-or-clang-compilers,如果您有权访问构建标志,则可以传入-Wno-conversion
在编译时禁用此警告。
从我的文档中:
其他 C 和 C++ 构建说明(例如:w/gcc
or clang
编译器):
-
Use -Wwarning-name
打开构建警告“警告名称”,并且-Wno-warning-name
关闭构建警告“警告名称”。-W
打开警告,并且-Wno-
关闭警告。以下是海湾合作委员会对此的说法(来源:https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html; https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html;添加了强调):
您可以请求许多特定警告,其选项开头为-W
, 例如-Wimplicit
请求有关隐式声明的警告。每个特定警告选项还有一个否定形式开始-Wno-
关闭警告;例如,-Wno-implicit
。本手册仅列出两种形式中的一种,以哪种形式为准not默认值。
关于 Visual Studio Code,我不使用那个 IDE,但是c_cpp_properties.json
文件似乎无法设置构建标志:https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference.
The tasks.json
然而,文件确实:https://code.visualstudio.com/docs/cpp/config-linux#_build-helloworldcpp 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
to the args
JSON 文件中的列表,如下所示:
"args": [
"-Wno-conversion",
"-g",
"${file}",
"-o", "${fileDirname}/${fileBasenameNoExtension}"
],
也可以看看:
- 如何在 Visual Studio Code 调试器中包含编译器标志? https://stackoverflow.com/questions/57173093/how-to-include-compiler-flags-in-the-visual-studio-code-debugger/57173879#57173879