首页 > 解决方案 > 无法在 Visual Studio Code 中构建 c++

问题描述

看起来是这样的,除了我跟着它,我仍然无法让它在 VS Code 中工作。这是我使用的目录:

C:\Users\EKI\Desktop\projects_cpp

按照说明,我将 .json 文件放在 \project_cpp.vscode 中,将 .cpp 文件放在 \projects_cpp\helloworld 中。

我的 .cpp 文件:

#include <iostream>


using namespace std;

int main()
{
   cout << "Hello World";
}

.json 文件如下:

启动.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
      {
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/helloworld.exe",
        "args": [],
        "stopAtEntry": true,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ]
      }
    ]
  }

设置.json

{
    "files.associations": {
        "ostream": "cpp"
    }
}

任务.json

{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "build hello world",
        "type": "shell",
        "command": "g++",
        "args": [
          "-g",
          "${file}",
          "-o",
          "$${workspaceFolder}\\${fileBasenameNoExtension}",
          ],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
  }

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

我尝试关闭受控文件夹访问,但仍然无法正常工作。

这是错误消息

执行任务:g++ -gc:\Users\EKI\Desktop\projects_cpp\helloworld\helloworld.cpp -o $C:\Users\EKI\Desktop\projects_cpp\helloworld <

g++.exe:错误:c:UsersEKIDesktopprojects_cpphelloworldhelloworld.cpp:没有这样的文件或目录 g++.exe:致命错误:没有输入文件编译终止。终端进程以退出代码终止:1

标签: c++visual-studio-code

解决方案


推荐阅读