我正在尝试运行一个简单的 hello world 应用程序。每当我尝试使用 g++ 构建时,都会出现以下错误。我无法生成 .exe 文件或其他任何文件。我使用 msys2 重新安装了 mingw。浏览教程等。出现同样的问题。下面提供的路径应该是正确的确保它
* Executing task: C/C++: g++.exe build active file
Starting build...
C:\msys64\mingw64\bin\g++.exe -fdiagnostics-color=always -g3 -Wall H:\VSCode\CPP\helloworld.cpp -o H:\VSCode\CPP\helloworld.exe
The system cannot find the path specified.
Build finished with error(s).
* The terminal process failed to launch (exit code: -1).
* Terminal will be reused by tasks, press any key to close it.
我从头到尾浏览了构建和调试 C++ 的教程,但仍然遇到同样的问题。 tasks.json代码如下。我坚持使用默认的“args”,但也有同样的问题。我复制了教程参数同样的问题。
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g3",
"-Wall",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
// "${fileDirname}" also gives the same problem.
"cwd": "C:\\msys64\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
},
"detail": "compiler: C:\\msys64\\mingw64\\bin\\g++.exe"
},
{
"type": "shell",
"label": "Run C/C++: g++.exe",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe -g3 -Wall \"${file}\" -o \"${fileDirname}\\${fileBasenameNoExtension}.exe\"",
"options": {
"cwd": "C:\\msys64\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"detail": "compiler: C:\\msys64\\mingw64\\bin\\g++.exe"
}
]
}
编辑: 你好世界.cpp
#include <iostream>
using namespace std;
int main(){
cout<<"Hello World!"<<endl;
return 0;
}
当我使用 CodeRunner 扩展使用运行代码运行它时,它运行正常,但运行/调试 C++ 代码给出了所提供的错误。 每当我尝试查看错误时,它都没有显示任何内容。
另一个编辑: 在 cmd 中运行
C:\msys64\mingw64\bin\g++.exe -fdiagnostics-color=always -g3 -Wall H:\VSCode\CPP\helloworld.cpp -o H:\VSCode\CPP\helloworld.exe
时,它会成功构建并生成 .exe 文件。
我已经安装了“Code Runner”扩展并从那里进行了编译。