vscode 支持c,c++编译调试方法

概述:tasks.jason   launch.json settings.json一定要有,没有就别想跑。还有就是c 和c++配置有区别,切记,下文有说

1.安装扩展插件。

2.安装编译器,gcc.我用的是x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z ,直接解压缩到你喜欢的目录,然后在环境变量里面添加即可。

3.找个目录,创建一个c或者c++文件。

4.将目录打开,可以选择在c/c++文件目录下右键,vscode打开即可。然后可以在目录下看到.vscode文件夹,下面就是一些脚本,可以改。

5.c和c++不太一样。在tasks.json 里面(如果没有,自己创建,一共三个文件,在第7点里面)。

6.碰到的问题点。如果细致一点,按下操作,如果不想麻烦,直接在第7点,文章末尾三个文件直接创建和我一样的就行了。

然后拷贝我的tasks目录进去就好了。

7.我的三个目录的代码是

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "compile",
            "command": "gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

settings.json

{
  "C_Cpp_Runner.cCompilerPath": "gcc",
  "C_Cpp_Runner.cppCompilerPath": "g++",
  "C_Cpp_Runner.debuggerPath": "gdb",
  "C_Cpp_Runner.cStandard": "",
  "C_Cpp_Runner.cppStandard": "",
  "C_Cpp_Runner.msvcBatchPath": "",
  "C_Cpp_Runner.useMsvc": false,
  "C_Cpp_Runner.warnings": [
    "-Wall",
    "-Wextra",
    "-Wpedantic",
    "-Wshadow",
    "-Wformat=2",
    "-Wcast-align",
    "-Wconversion",
    "-Wsign-conversion",
    "-Wnull-dereference"
  ],
  "C_Cpp_Runner.msvcWarnings": [
    "/W4",
    "/permissive-",
    "/w14242",
    "/w14287",
    "/w14296",
    "/w14311",
    "/w14826",
    "/w44062",
    "/w44242",
    "/w14905",
    "/w14906",
    "/w14263",
    "/w44265",
    "/w14928"
  ],
  "C_Cpp_Runner.enableWarnings": true,
  "C_Cpp_Runner.warningsAsError": false,
  "C_Cpp_Runner.compilerArgs": [],
  "C_Cpp_Runner.linkerArgs": [],
  "C_Cpp_Runner.includePaths": [],
  "C_Cpp_Runner.includeSearch": [
    "*",
    "**/*"
  ],
  "C_Cpp_Runner.excludeSearch": [
    "**/build",
    "**/build/**",
    "**/.*",
    "**/.*/**",
    "**/.vscode",
    "**/.vscode/**"
  ],
  "C_Cpp_Runner.useAddressSanitizer": false,
  "C_Cpp_Runner.useUndefinedSanitizer": false,
  "C_Cpp_Runner.useLeakSanitizer": false,
  "C_Cpp_Runner.showCompilationTime": false,
  "C_Cpp_Runner.useLinkTimeOptimization": false,
  "C_Cpp_Runner.msvcSecureNoWarnings": false
}

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "C/C++",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "miDebuggerPath": "gdb.exe",
      "preLaunchTask": "compile",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    },
    {
      "name": "C/C++ Runner: Debug Session",
      "type": "cppdbg",
      "request": "launch",
      "args": [],
      "stopAtEntry": false,
      "externalConsole": true,
      "cwd": "d:/test",
      "program": "d:/test/build/Debug/outDebug",
      "MIMode": "gdb",
      "miDebuggerPath": "gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

8. 参数解释

相关推荐

  1. vscode编译调试sln工程

    2023-12-30 09:38:02       45 阅读
  2. VSCode Python调试运行:json编写

    2023-12-30 09:38:02       30 阅读
  3. vscode编译调试wsl环境的c语言程序

    2023-12-30 09:38:02       9 阅读
  4. vscode 调试

    2023-12-30 09:38:02       6 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-30 09:38:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-30 09:38:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-30 09:38:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-30 09:38:02       20 阅读

热门阅读

  1. TCP/UDP协议

    2023-12-30 09:38:02       36 阅读
  2. 百度地图再vue中的引入方式

    2023-12-30 09:38:02       44 阅读
  3. 《基于 Vue 组件库 的 Webpack5 配置》- 总结

    2023-12-30 09:38:02       36 阅读
  4. FreeRTOS学习--61讲 内存管理

    2023-12-30 09:38:02       36 阅读
  5. 【蓝桥杯】比赛大纲整理

    2023-12-30 09:38:02       31 阅读
  6. 前端使用a标签下载非同源文件(备选方案)

    2023-12-30 09:38:02       44 阅读
  7. shiro反序列化与fastjson反序列化漏洞原理

    2023-12-30 09:38:02       48 阅读