'g' 不是内部或外部命令、可运行程序或批处理文件。

新手上路,请多包涵

我正在尝试使用 C++ 编译器设置 VScode 按照本教程 在此处输入链接描述

我遇到的问题是(通过使用代码运行器运行代码)

‘g++’ 不是内部或外部命令、可运行程序或批处理文件。 在此处输入图像描述

如果我使用调试选项运行我遇到了这个问题

preLaunchTask ‘build & run file’ 以退出代码 1 终止。 在此处输入图像描述

这是我的“c_cpp_properties.json”

 {
"configurations": [
    {
        "name": "Win32",
        "intelliSenseMode": "clang-x64",
        "defines": [
            "_DEBUG",
            "UNICODE",
            "__GNUC__=7",
            "__stdcall=attribute((stdcall))",
            "__cdecl=__attribute__((__cdecl__))",
            "__cplusplus=201703L"
        ],
        "includePath": [
            "${workspaceFolder}/include",
            "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++",
            "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32",
            "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/backward",
            "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include",
            "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../include",
            "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed",
            "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include"
        ],
        "browse": {
            "path": [
                "${workspaceFolder}/include",
                "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++",
                "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32",
                "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/backward",
                "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include",
                "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../include",
                "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed",
                "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include"
            ],
            "limitSymbolsToIncludedHeaders": false,
            "databaseFilename": ""
        },
        "cStandard": "c11",
        "cppStandard": "c++17"
    }
],
"version": 4

}

这是我的“launch.json”

 {
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Run C/C++",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": true,
      "MIMode": "gdb",
      "miDebuggerPath": "C:/MinGW64/bin/gdb.exe",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": false
        }
      ],
      "preLaunchTask": "build & run file"
    },
    {
      "name": "Debug C/C++",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": true,
      "MIMode": "gdb",
      "miDebuggerPath": "C:/MinGW64/bin/gdb.exe",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": false
        }
      ],
      "preLaunchTask": "build & debug file"
    }
  ]
}

这是我的“tasks.json”

 {
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build & debug file",
      "type": "shell",
      "command": "g++",
      "args": [
        "-g",
        "-o",
        "${fileBasenameNoExtension}",
        "${file}"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    },
    {
      "label": "build & run file",
      "type": "shell",
      "command": "g++",
      "args": [
        "-o",
        "${fileBasenameNoExtension}",
        "${file}"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

我只是想学习C++,我在互联网上尝试了很多天,但我仍然无法修复它请帮助。谢谢你。

原文由 S.Xu 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.3k
1 个回答

首先,打开此页面并在您的系统上安装和配置 Mingw:

http://www.mingw.org/wiki/getting_started

下载并安装后,您必须使用此链接将 Mingw->bin 添加到您的路径:

https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/

然后为确保,在 CMD 中键入 g++ --versiongcc --version

那么您可以将此链接用于您的目的。

如需更多帮助,请使用

https://code.visualstudio.com/docs/cpp/config-mingw

这个链接可能对你很有用

原文由 MohammadHossein 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题