VS code 调试C C++


参考网址:

https://www.cnblogs.com/lidabo/p/5888997.html     在Linux中使用VS Code编译调试C++项目

https://www.jianshu.com/p/2700f2b93b14         2019 linux下vscode C++配置

https://www.cnblogs.com/dotnetcrazy/p/6661921.html    1.跨平台开发之~ VSCode开发第一个C程序

1、在vscode里面下载c/c++官方插件:
插件

注意:C / C ++扩展不包括C ++编译器或调试器。您需要安装这些工具或使用计算机上已安装的工具。流行的C ++编译器是用于Windows的mingw-w64,用于macOS的XCode的 Clang 和用于Linux的GCC。确保您的编译器可执行文件位于您的平台路径中,以便扩展程序可以找到它。该扩展还支持Windows的Windows子系统

C/C++            为必装,提供C/C++支持
Code Runner           必装,提供编译后程序的运行环境
C/C++ Snippets          建议 提供一些常用的C/C++片段,如for(;;){},安装后写代码方便(tip.如果想要添加自己写的代码段可以点左下角齿轮->用户代码片段)
EPITECH C/C++ Headers  为C/C++文件添加头部(包括作者、创建和修改日期等),并为.h头文件添加防重复的宏
File Templates                   文件模板,可以自己添加文件模板
GBKtoUTF8 GBK          编码文件转换为UTF-8
Include Autocomplete        头文件自动补全
One Dark Pro                一个好看的vscode主题
Easy C++ projects      提供一个简单的编译模式,开启后只要安装了C/C++扩展就可以直接编译运行,建议不用,因为不能自己配置参数

2. 新建测试文件test.c

#include <stdlib.h>
#include <stdio.h>

void test() 
{
    printf("this is my test!!!");
} 

int main()
{
    printf("this is my test!!!");

    return 0;
}

3.  F5 或者 点击debug图标

4. 点击设置图片,出现 选择环境,选择 c++

5.生成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) Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "${workspaceFolder}/a.out",
            "processId": "${command:pickProcess}",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

6.Ctrl+Shift+B,输入Task    选择Others  添加tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "c++",
            "type": "shell",
            "command": "g++",
            "args": ["-g", "/home/hkjc/Desktop/projects/C/test.c"],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

7.Ctrl+Shift+B生成a.out,  F5即可调试 !

 

/***************************************************多个文件编译******************************************************/

https://blog.csdn.net/qq_34347375/article/details/81137962

1.   打开设置找到   code-runner.executorMap
    因为我们是通过makefile文件来进行编译链接源程序的,所以在这里更改如下:

"c": "cd $dir && make $fileNameWithoutExt && ./$fileNameWithoutExt && make clean",
"cpp": "cd $dir && make $fileNameWithoutExt && ./$fileNameWithoutExt && make clean",

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM