VS Code中自定义C文件编译命令参数问题求助
解决VS Code中C文件自定义编译参数的问题
问题说明
我一直尝试在VS Code中自定义C文件的编译命令参数,但始终无法解决。我希望通过添加-Wall获取编译警告,使用-std=c99启用C99标准,目标编译命令为:
gcc -Wall -std=c99 hello.c -o hello
我推测需要在tasks.json文件中添加参数,但操作起来十分困惑。以下是我的tasks.json文件:
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe build active file", "command": "C:\\MinGW\\bin\\gcc.exe", "args": [ "-fdiagnostics-color=always", "-Wall", "std=c99", "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }
问题修复
你的tasks.json里有一个明显错误:std=c99缺少了参数前缀-,应该写成-std=c99。修正后的完整tasks.json如下:
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe build active file", "command": "C:\\MinGW\\bin\\gcc.exe", "args": [ "-fdiagnostics-color=always", "-Wall", "-std=c99", "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }
验证方法
修改完成后保存tasks.json,回到C代码文件,按下Ctrl+Shift+B执行编译任务,此时gcc会按照-Wall输出所有警告,并以C99标准编译代码。你可以在终端中查看实际执行的编译命令,确认是否和目标命令一致。
内容的提问来源于stack exchange,提问作者Furkan23
相关产品推荐
相关产品推荐

