【问题标题】:Visual Studio Code cannot find the g++.exe (Windows 10)Visual Studio Code 找不到 g++.exe (Windows 10)
【发布时间】:2019-05-10 08:05:03
【问题描述】:

我正在按照tutorial 在我的 Windows 电脑上设置 vs 代码。

我通过从其他文件夹调用 g++ 来检查路径是否正确。

但我在 vs 代码上不断收到此错误:

Cannot find "C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw64\bin\g++.exe".

尝试从helloworld.cpp 所在的文件夹中使用命令提示符运行g++ helloworld.cpp 不会给出错误或输出。

谁能告诉我我错过了什么?

编辑:

代码实际上已经编译好了。 它生成 a.exe 并且运行良好。 问题是我需要将它集成到 vs 代码中。 我猜它类似于this,但我不确定。

c_cpp_properties.json

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

}

tasks.json已更正

{
// See https://go.microsoft.com/fwlink/?LinkId=733558 
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "type": "shell",
        "label": "g++.exe build active file",
        "command": "g++",
        "args": [
            "-g",
            "-o",
            "helloworld",
            "helloworld.cpp"
        ],

        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
]

}

tasks.json

    {
// See https://go.microsoft.com/fwlink/?LinkId=733558 
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "type": "shell",
        "label": "g++.exe build active file",
        "command": "g++",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}.exe",
            "helloworld",
            "helloworld.cpp"
        ],
        "options": {
            "cwd": "C:/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw64/bin/"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
]

}

settings.json

{
"[cpp]": {},
"terminal.integrated.shell.windows": "C:\\cygwin64\\bin\\bash.exe"

}

launch.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": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "miDebuggerPath": "C:/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw64/bin/g++.exe",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    }
]

}

【问题讨论】:

    标签: c++ visual-studio-code windows-10


    【解决方案1】:

    您确定路径正确吗?通常如果它说找不到文件,那是因为文件不存在。

    当我安装 MinGW-W64 时,它会转到 C:(...)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32 。所以我想你的路径是错误的消息说(除非你手动更改它):它不应该在 mingw64\bin 中,而应该在 mingw32\bin 中。

    【讨论】:

    • 我检查 windows 中的路径是否正确。是的,我需要更正 json 文件中的路径。更正后,错误代码现在是1.之前是2.错误:g++.exe:错误:f:XXXYYYYcpphelloworld.cpp:没有这样的文件或目录,它似乎无法识别/字符
    【解决方案2】:

    tasks.json 你有

    "tasks": [
        {
            ...
            "command": "g++",
            ...
            "options": {
                "cwd": "C:/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw64/bin/"
            },
            ...
    

    但是你应该使用你当前的工作目录

    "cwd": "${workspaceFolder}"
    

    【讨论】:

    • 我想我发现了自己的错误。上面的tasks.json我已经更新了。
    【解决方案3】:

    有效吗? 我认为你的 tasks.json 应该是:

        {
            // See https://go.microsoft.com/fwlink/?LinkId=733558 
            // for the documentation about the tasks.json format
            "version": "2.0.0",
            "tasks": [
                {
                    "type": "shell",
                    "label": "g++.exe build active file",
                    "command": "g++",
                    "args": [
                        "-g",
                        "helloworld.cpp",
                        "-o",
                        "helloworld"
                    ],
                    "options": {
                        "cwd": "${workspaceFolder}"
                    },
                    "problemMatcher": [
                        "$gcc"
                    ],
                    "group": {
                        "kind": "build",
                        "isDefault": true
                    }
                }
            ]
        }
    

    关键部分是添加正确的 cwd 选项。在此配置中,“helloworld”应该在您的工作区文件夹下。如果不是这种情况,请相应地更新 helloworld.cpp 的路径。

    【讨论】:

      猜你喜欢
      • 2020-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-26
      • 1970-01-01
      • 1970-01-01
      • 2016-04-03
      • 2020-02-27
      相关资源
      最近更新 更多