关于visual-studio-code:Macwindows-下Visual-Studio-code-debug-c配置

9次阅读

共计 1386 个字符,预计需要花费 4 分钟才能阅读完成。

mac 教程

先决条件#

要胜利实现本教程,您必须执行以下操作:

  1. 在 macOS 上装置 Visual Studio Code。
  2. 为 VS Code 装置 C ++ 扩大。您能够通过在“扩大”视图(⇧⌘X)中搜寻“c ++”来装置 C / C ++ 扩大。

确保已装置 Clang #

您的 Mac 上可能曾经装置了 Clang。要验证它是否正确,请关上 macOS 终端窗口,而后输出以下命令:

clang --version
  1. 如果未装置 Clang,请输出以下命令以装置命令行开发人员工具:
xcode-select --install

创立工程

1. 新建一个文件夹, 用 vscode 关上此文件夹,到此我的项目创立实现.

配置 c ++ 编译项

倡议间接装置 native debug 插件, 官网给出的本人配置的办法较繁琐

debug

native debug 插件装置之后, 能够间接按 f5 键就行调试, 第一次启动的时候会让你抉择环境, 抉择 c ++(GDB/LLDB)(见图 1 -1)、抉择配置, 抉择 clang++- 生成和调试流动文件 (见图 1 -2)

            图 1 -1

            图 1 -2

会主动生成 tasks.json 和 launch.json
编译多文件的时候须要在在 tasks.jso -args 退出文件门路,且批改输入文件名, 不能和文件夹下的文件重名, 改变后如下:

{
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "*.cpp",//cpp 文件门路
                "*.c",// c 文件门路
                "main/*.c",//main 下的 c 门路
                "-g",
                "-o",
                 // cmakeTest 不能和以后门路下的重名
                "${fileDirname}/cmakeTest"
            ],
            "options": {"cwd": "${workspaceFolder}"
            },
            "problemMatcher": ["$gcc"],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}

因为下面批改了生成的程序名,须要同步批改 launch.json 中 program 的值

{
    // 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": "clang++ - 生成和调试流动文件",
            "type": "cppdbg",
            "request": "launch",
            // 和 task.json 输入程序文件一至
            "program": "${fileDirname}/cmakeTest",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: clang++ build active file"
        }
    ]
}
正文完
 0