我第一次尝试使用 Visual Studio Code,但我的 C++ 无法编译。
我已经将 mingw 的 bin 和 bash.exe 从 MSYS2 添加到我的 PATH。我的所有代码都在同一个目录中,直接来自微软的指南https://code.visualstudio.com/docs/cpp/config-mingw(我确实改变了我的路径)。我的所有文件也都在同一目录中。
我已经包含了文件
你好世界.cpp:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World";
}
任务.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
}
}
]
}
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
}
启动.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
}
]
}
]
}
该文件不会构建,我不断收到相同的错误消息:
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
}
}
]
}
这里${file}
给出了带有扩展名(.cpp) 的文件的完整路径,${workspaceFolder}
并且${fileBasenameNoExtension}
几乎不言自明。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句