【VSCode】Windows下VSCode编译调试c/c++

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/c_duoduo/article/details/51615381
————————– 2018.03.27 更新————————-
便携版已更新,点此获取便携版
已知BUG:中文目录无法正常调试
用于cpptools 0.15.0插件的配置文件更新
新的launch.json

// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team        
// ${file}: the current opened file                     
// ${fileBasename}: the current opened file's basename 
// ${fileDirname}: the current opened file's dirname    
// ${fileExtname}: the current opened file's extension  
// ${cwd}: the current working directory of the spawned process

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "preLaunchTask": "build",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/Program Files (x86)/MinGW/bin/gdb.exe", // GDB的路径,注意替换成自己的路径
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }]
}

新的tasks.json

// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team        
// ${file}: the current opened file                     
// ${fileBasename}: the current opened file's basename 
// ${fileDirname}: the current opened file's dirname    
// ${fileExtname}: the current opened file's extension  
// ${cwd}: the current working directory of the spawned process


{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "windows": {
                "command": "g++",
                "args": [
                    "-ggdb",
                    "\"${file}\"",
                    "--std=c++11",
                    "-o",
                    "\"${fileDirname}\\${fileBasenameNoExtension}.exe\""
                ]
            }
        }
    ]
}

懒得自己配置或自己配置出现不明问题的朋友可以点这里:
【VSCode】Windows下VSCode便携式c/c++环境
http://blog.csdn.net/c_duoduo/article/details/52083494
下载解压即可食用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在 Windows 下使用 Visual Studio Code 配置 C/C++ 编程环境需要以下步骤: 1. 下载并安装 Visual Studio Code。 2. 安装 C/C++ 扩展,在扩展面板中搜索 "c/c++" 并安装。 3. 安装 GCC 编译器,可以使用 MinGW 或 Cygwin。 4. 配置环境变量,将 GCC 的 bin 目录添加到 PATH 中。 5. 在 VSCode配置 tasks.json 和 launch.json 文件以使用 GCC 编译调试程序。 6. 可以在 VSCode 中使用快捷键编译调试代码。 ### 回答2: Windows下使用VS Code进行C/C++的开发,需要安装C/C++插件和编译器,并进行相应的配置。 1. 安装VS Code 首先,需要从VS Code官网下载安装VS Code,安装好后可以在桌面上打开VS Code。 2. 安装C/C++插件 在VS Code中,可以使用插件来扩展其功能,因此需要安装C/C++插件来支持C/C++的开发。在VS Code中,点击左侧的“扩展”图标,搜索“C/C++”插件,点击安装即可。 3. 安装编译编译器是用来将C/C++代码转换为可执行程序的工具,Windows下可以使用多种编译器,例如MinGW、Visual Studio等。这里以MinGW为例。 首先,需要从MinGW官网下载安装MinGW,并选择安装最新版本的MinGW,安装完成后,需要将MinGW的bin目录添加到系统的环境变量PATH中,也可以手动在VS Code中配置MinGW路径。 4. 配置VS Code 在VS Code中,需要对C/C++的开发环境进行相应的配置,包括配置调试环境、编译器等。 4.1. 配置调试环境 在菜单栏中选择“调试”->“添加配置”,选择C++(GDB/LLDB),在“launch.json”文件中加入以下代码: { "version": "0.2.0", "configurations": [ { "name": "C/C++ Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceRoot}/a.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/MinGW/bin/gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "g++ build active file", "miDebuggerArgs": "--fullname" } ] } 其中,需要修改“miDebuggerPath”为正确的MinGW路径。 4.2. 配置编译器 在菜单栏中选择“文件”->“首选项”->“设置”,在“settings.json”文件中加入以下代码: { "C_Cpp.default.compilerPath": "C:/MinGW/bin/g++.exe", "C_Cpp.default.includePath": ["${workspaceFolder}/**"] } 其中,需要修改“compilerPath”为正确的MinGW路径。 至此,Windows下VS Code配置C/C++的开发环境已经完成,可以开始进行C/C++的开发。在VS Code中创建C/C++文件,编写代码、编译、运行和调试都可以直接在VS Code中进行。 ### 回答3: VSCode是一个由微软公司开发的轻量级跨平台的集成开发环境,它支持多种编程语言和开发工具的插件,并且可以进行自定义配置。在Windows操作系统中,VSCode常用于开发C/C++程序。接下来,我将介绍如何在Windows配置VSCode以开发C/C++程序。 第一步:安装Visual Studio Build Tools 和 C/C++编译器 在Windows中,C/C++编译器需要与Visual Studio Build Tools一起安装。下载安装Visual Studio Build Tools,可以在https://visualstudio.microsoft.com/downloads/中下载Visual Studio Build Tools程序。 安装后,在VSCode中按下F1,在显示的命令控制台中键入“C/C++: Edit Configurations”。然后将configurations.json文件复制到新文件夹。 第二步:采用插件方法 将VSCode扩展库中的”C++”和”C/C++ Clang Command Adapter”两个插件安装到VSCode中。安装插件时,可以在VSCode的Extensions面板中输入关键词”C++”和”C/C++ Clang Command Adapter”寻找和安装。安装完成后,重启VSCode。 第三步:配置环境变量 将C/C++工具链的路径添加到系统环境变量中,使得VSCode可以在命令终端中调用C/C++编译器。 具体方法是在Windows系统环境变量中添加以下路径:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin。 第四步:创建和编译C/C++项目 在VSCode中创建一个新的C/C++项目,如下所示: 在这里,可以新建一个文件c文件,进行g++进行编译;也可以新建一个cpp文件,然后用g++或clang++进行编译。在创建文件结束后,按下F5键启动调试过程,或按下SHIFT + F5终止调试,可进行程序调试。 总结: 在Windows中,配置VSCode以开发C/C++程序需要完成以下四个步骤:安装Visual Studio Build Tools和C/C++编译器,采用插件方法,配置环境变量,创建和编译C/C++项目。使用VSCode可以方便地开发C/C++程序,提高编程效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值