Visual Code C ++没有这样的文件或目录

时间:2016-08-11 12:13:09

标签: g++ visual-studio-code

感谢您阅读我的问题。我刚开始使用目前运行1.4版的Visual Code。 我将它用于C ++并使用mingw(g ++)进行编译。我创建了一个简单的“hello world”示例。但我无法编译代码。 互联网上没有很多帮助。我浏览了c ++扩展的文档,但没有帮助。

我收到以下错误: “g ++:错误:Makefile:没有这样的文件或目录”

以下是tasks.json的外观:

{
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"tasks": [
    {
        "taskName": "Makefile",
        // Make this the default build command.
        "isBuildCommand": true,
        // Show the output window only if unrecognized errors occur.
        "showOutput": "always",
        // No args
        "args": ["all"],

        // Use the standard less compilation problem matcher.
        "problemMatcher": {
            "owner": "cpp",
            "fileLocation": ["relative", "${workspaceRoot}"],
            "pattern": {
                "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                "file": 1,
                "line": 2,
                "column": 3,
                "severity": 4,
                "message": 5
            }
        }
    }
]

}

以下是Launch.Json的外观

{
"version": "0.2.0",
"configurations": [
    {
        "name": "C++ Launch (GDB)",
        "type": "cppdbg",
        "request": "launch",
        "launchOptionType": "Local",
        "miDebuggerPath": "C:/mingw64/bin/",
        "targetArchitecture": "x64",
        "program": "${workspaceRoot}/main.cpp",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "environment": []
    },
    {
        "name": "C++ Attach (GDB)",
        "type": "cppdbg",
        "request": "launch",
        "launchOptionType": "Local",
        "miDebuggerPath": "C:/mingw64/bin/",
        "targetArchitecture": "x64",
        "program": "${workspaceRoot}/main.cpp",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "environment": [],
        "processId": "enter program's process ID"
    }
]

}

我也遇到以下错误: spawn C:/Users/username/.vscode/extensions/ms-vscode.cpptools-0.5.0/debugAdapters/OpenDebugAD7 ENOENT。停止调试适配器。

如果你们知道我做错了什么,请告诉我。

谢谢。 阿维

1 个答案:

答案 0 :(得分:0)

你的项目应该有一个makefile来编译。

尝试在项目根目录中创建一个简单的makefile

示例makefile:

all: g++ main.cpp -o main.exe

运行make all以编译或使用任务:运行任务 - 生成文件

launch.json中的"program": "${workspaceRoot}/main.cpp"应指向已编译的输出"program": "${workspaceRoot}/main.exe",此处的"miDebuggerPath": "C:/mingw64/bin/",应为"miDebuggerPath": "C:/mingw64/bin/gdb.exe"