gpt4 book ai didi

visual-studio-code - vscode 在构建 c 文件时报告事件文件不是 C 或 C++ 源文件

转载 作者:行者123 更新时间:2023-12-05 05:51:35 26 4
gpt4 key购买 nike

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 文件,该文件夹是工作区文件夹。问题的原因可能是什么?

最佳答案

this 所示Sean McManus 的回复,您需要删除 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

关于visual-studio-code - vscode 在构建 c 文件时报告事件文件不是 C 或 C++ 源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70359209/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com