Visual Studio代码找不到g ++。exe(Windows 10)

时间:2019-05-10 08:05:03

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

我正在按照此tutorial在Windows pc上设置vs代码。

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

但是我仍然在与代码有关的错误:

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

试图从g++ helloworld.cpp所在的文件夹使用命令提示符运行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
            }
        ]
    }
]

}

3 个答案:

答案 0 :(得分:0)

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

当我安装MinGW-W64时,它转到C:(...)\ mingw-w64 \ i686-8.1.0-posix-dwarf-rt_v6-rev0 \ mingw32。因此,我认为您的路径是错误的(如消息所示)(除非您手动更改):它不应位于mingw64 \ bin中,而应位于mingw32 \ bin中。

答案 1 :(得分:0)

tasks.json中,您拥有

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

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

"cwd": "${workspaceFolder}"

答案 2 :(得分:0)

有效吗? 我认为您的task.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的路径。