问题
I'm working on VS-Code with C/C++ intellisense[gcc-arm]. When I do compile , The VS-Code show me hundred of warning like that:
Conversion from 'int' to u16_t{aka 'short unsigned int'} may change value [-Wconversion]
I do not want the VSCode show me those warning. But I have no permission to edit the source code. So, Is the any way to disable those warning by adding some arg to c_cpp_properties.json file?
回答1:
Referring to my own reference document here, if you have access to the build flags, you can pass in -Wno-conversion
to disable this warning at compile time.
From my document:
Additional C and C++ build notes (ex: w/
gcc
orclang
compilers):
Use
-Wwarning-name
to turn ON build warning "warning-name", and-Wno-warning-name
to turn OFF build warning "warning-name".-W
turns a warning ON, and-Wno-
turns a warning OFF. Here's what gcc has to say about it (source: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html; emphasis added):You can request many specific warnings with options beginning with
-W
, for example-Wimplicit
to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning-Wno-
to turn off warnings; for example,-Wno-implicit
. This manual lists only one of the two forms, whichever is not the default.
Regarding Visual Studio Code, I do not use that IDE, but the c_cpp_properties.json
file appears to have no ability to set build flags: https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference.
The tasks.json
file, however, does: https://code.visualstudio.com/docs/cpp/config-linux#_build-helloworldcpp.
Here's their example:
{ "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 } } ] }
So, it looks like you could add -Wno-conversion
to the args
list in the JSON file, like this:
"args": [
"-Wno-conversion",
"-g",
"${file}",
"-o", "${fileDirname}/${fileBasenameNoExtension}"
],
See also:
- How to include compiler flags in the Visual Studio Code debugger?
来源:https://stackoverflow.com/questions/65366489/how-to-disable-warning-from-vs-code-gcc-compiler-not-use-pragma