【发布时间】:2020-12-19 06:19:34
【问题描述】:
这是我试图构建和执行的代码。
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
cout << "Hello World";
return 0;
}
我可以使用命令编译和运行它
directory path:// g++ -g hello.cpp
./a.exe
我现在制作了一个tasks.json 文件,这样我就不必每次都运行上述两个命令,并且.exe 文件也与.cpp 文件命名相同。
这是我面临的错误: image for build error in VSCode terminal
如果有人知道解决此问题的方法,请帮助我。
如果您需要tasks.json 文件内容,请告诉我。我会把它们放在这里。
Tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ (gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "C:/Users/H.P/.vscode/CC++_gcc_Compiler/bin/gdb.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/Users/H.P/.vscode/CC++_gcc_Compiler/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
【问题讨论】:
-
嗯,错误说“没有这样的文件或目录”。那么,您是否检查过您的文件是否存在?并且它存在于正确的路径上?
-
@linuxartisan 是的,文件存在。我能够使用
g++ -g hellp.cpp和./a.exe命令成功编译和执行 -
请提供tasks.json和launch.json文件。
-
@mgonnav 添加了它。
-
我在 launch.json 中看不到 C++ 的启动配置。但抛开这些不谈,如果你从 tasks.json 中删除选项,你还有问题吗?
标签: c++ gcc visual-studio-code