当前位置:   article > 正文

VScode配置支持c++11和配置自动编译调试功能_vscode支持c++11

vscode支持c++11



提示:以下是本篇文章正文内容,下面案例可供参考

1 在工程目录下新建.vscode目录

在这里插入图片描述

2 在.vscode目录下创建c_cpp_properties.json文件内容如下

{
    "configurations": [
        {
          "name": "Ubuntu",
          "includePath": ["${workspaceFolder}/**", "${workspaceFolder}/include/*"], // 需要更具自己的实际工程添加定义的头文件路径
          "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
          "windowsSdkVersion": "10.0.17763.0",
          //"compilerPath": "",   // g++所在路径
          "cStandard": "c11",
          "cppStandard": "c++11",
          "intelliSenseMode": "${default}"
        }
      ],
      "version": 4
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

2.1 添加c_cpp_properties.json后,关于c++11的相关类型或字段函数都可以正常识别了(如:atomic,auto,to_string等)

3 在.vscode目录下创建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++ - 生成和调试文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/SimulateSystemServer",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build", // 要执行的任务的label名
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

4 在.vscode目录下创建tasks.json文件内容如下

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "options": {
        "cwd": "${workspaceFolder}/build"
    },
    "tasks": [
        {
            "label": "cmake",
            "type": "shell",
            "command": "cmake",
            "args": [
                ".."
            ]
        },
        {
            "label": "make",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "command": "make", // windows: mingw32-make
            "args": [

            ]
        },
        {
            "label": "Build",
            "dependsOrder": "sequence", // 按列出顺序执行任务依赖项
            "dependsOn":[
                "cmake",
                "make"
            ]

        }
    ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

5 在CMakeLists.txt添加如下内容,才能正常进行调试

set(CMAKE_BUILD_TYPE Debug)
  • 1

6 验证,在main中打一个断点,然后F5调试运行

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/65831
推荐阅读
相关标签
  

闽ICP备14008679号