VSCode + make + makefile +

2019-05-17  本文已影响0人  阿_贵

一、VSCode 自带

新建文件夹 Test -> VSCode 打开 Test -> 新建文件 main.cpp -> 

DEBUG “执行按钮”右边“add configuration...”  选择 “g++ build and debug” -> 

VSCode 自动生成 tasks.json 和 laugh.json 即可断点调试

二、makefile 文件

1. VSCode 新建文件 makefile 内容如下:

.default: all

all: main

main: main.o

    g++ -Wall -Werror -std=c++14 -g -O -o $@ $^

%.o: %.cpp

    g++ -Wall -Werror -std=c++14 -g -O -c $^

clean:

    rm -rf qwirkle *.o *.dSYM

此时,打开命令行,make,可以生成可执行文件

2. task.json 改成如下:

{

    "tasks": [

        {

            "type": "shell",

            "label": "shell",

            "command": "/usr/bin/make",

        }

    ],

    "version": "2.0.0"

}

3. 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": "g++ build and debug active file",  // 配置名称,将会在启动配置的下拉菜单中显示

            "type": "cppdbg",

            "request": "launch",  // 请求配置类型,可以为launch(启动)或attach(附加)

            "program": "${fileDirname}/main",  //将要进行调试的程序的路径,与 makefile 中的 main 一致

            "args": [],

            "stopAtEntry": true,  // 设为true时程序将暂停在程序入口处

            "cwd": "${workspaceFolder}",

            "environment": [],

            "externalConsole": true, // 调试时是否显示控制台窗口,必须为true显示控制台,才能输入,交互

            "MIMode": "lldb",  // 指定连接的调试器,可以为gdb或lldb。

            "preLaunchTask": "shell"   //调试会话开始前执行的任务,一般为编译程序。与 tasks.json 的 label 一致

        }

    ]

}

点击 VSCode 执行按钮即可断点调试,找到弹出的窗口,即可输入,交互

注意断点打到  std::cout<<"start"<<std::endl;  不停留

上一篇 下一篇

猜你喜欢

热点阅读