Joh*_*ter 2 c++ windows mingw-w64 visual-studio-code
我第一次尝试使用 Visual Studio Code,但我的 C++ 无法编译。
我已经将 MSYS2 中的 mingw 的 bin 和 bash.exe 添加到我的 PATH 中。我的所有代码都位于同一目录中,并且直接来自微软的指南https://code.visualstudio.com/docs/cpp/config-mingw(我确实更改了我的路径)。我的所有文件也都在同一目录中。
我已经包含了该文件
你好世界.cpp:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World";
}
Run Code Online (Sandbox Code Playgroud)
任务.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"helloworld",
"helloworld.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"defines": [
"_DEBUG",
"UNICODE"
],
"compilerPath": "C:\\Mingw-w64\\mingw32\\bin\\g++.exe",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
Run Code Online (Sandbox Code Playgroud)
启动.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Mingw-w64\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
该文件无法构建,并且我不断收到相同的错误消息:
g++.exe:错误:helloworld.cpp:没有这样的文件或目录 g++.exe:致命错误:没有输入文件编译终止。终端进程终止并退出代码:1
似乎编译器无法找到源文件,更新tasks.json以使用完整路径编译程序,
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",//Just
"-o",//edit
"${workspaceFolder}\\${fileBasenameNoExtension}"//these
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
这里${file}给出了带有扩展名(.cpp)的文件的完整路径,${workspaceFolder}并且${fileBasenameNoExtension}也几乎是不言自明的。
| 归档时间: |
|
| 查看次数: |
16853 次 |
| 最近记录: |