vscode在构建c程序时报告错误。错误消息如下所示。
Cannot build and debug because the active file is not a C or C++ source file.
The terminal process failed to launch (exit code: -1).任务配置文件如下所示。
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"/home/xxx/tmp/test/main.c"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}我在/home/xxx/tmp/test文件夹下有一个名为main.c的c文件,它是工作区文件夹。问题的原因可能是什么?
发布于 2021-12-21 19:50:59
从Sean的这回复中可以看到,您需要删除tasks.json中的所有${file}引用,例如:
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
}更改为
"args": [
"-g",
"test.cpp",
"-o",
"libs/test.o"
],
"options": {
"cwd": "${fileDirname}"
}并将构建类型从cppBuild更改为shell。
https://stackoverflow.com/questions/70359209
复制相似问题