VSCode在Linux和Windows调试C/C++程序
2017-02-21 12:17
489 查看
VSCODE是一个文本编辑器,不具备编译功能,但是可以调用外部编译器调试器来实现调试功能
Linux 使用GDB,Windows 可以安装minGW,
写好测试文件main.cpp , 用vscode 打开代码所在文件夹,切换到调试界面,点击配置按钮
选择 C++(GDB/LLDB) for Windows or Linux
或者选择 C++(Windows) for Windows
弹出默认的launch.json文件,在此基础上修改
“program” : 要调试运行的程序,修改为程序名,或 {file}.o / {file}.exe
根据当前系统在"linux"或者“Windows” 分别添加 gdb的安装路径
"miDebuggerPath": "/usr/bin/gdb",
或
"miDebuggerPath": "D:/MinGW/bin/gdb.exe",
下面多余的 C++ Attach项可以整个删除,也可忽略,修改好后的launch.json文件如下
然后点击调试按钮,提示 没有配置task runner,点击配置
选择Others或任一个,弹出默认tasks.json文件,用下面的文件覆盖原来的内容
command: gcc , g++
args: 编译参数
最后再次点调试按钮,即可成功运行调试,可以添加断点,查看变量,堆栈等常用调试功能
Linux 使用GDB,Windows 可以安装minGW,
写好测试文件main.cpp , 用vscode 打开代码所在文件夹,切换到调试界面,点击配置按钮
选择 C++(GDB/LLDB) for Windows or Linux
或者选择 C++(Windows) for Windows
弹出默认的launch.json文件,在此基础上修改
“program” : 要调试运行的程序,修改为程序名,或 {file}.o / {file}.exe
根据当前系统在"linux"或者“Windows” 分别添加 gdb的安装路径
"miDebuggerPath": "/usr/bin/gdb",
或
"miDebuggerPath": "D:/MinGW/bin/gdb.exe",
下面多余的 C++ Attach项可以整个删除,也可忽略,修改好后的launch.json文件如下
//launch.json { "version": "0.2.0", "configurations": [ { "name": "C++ Launch", "type": "cppdbg", "request": "launch", "program": "${file}.o", "args": [], "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true, "preLaunchTask": "g++", "linux": { "miDebuggerPath": "/usr/bin/gdb", "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] }, "osx": { "MIMode": "lldb" }, "windows": { "miDebuggerPath": "D:/MinGW/bin/gdb.exe", "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } } ] }
然后点击调试按钮,提示 没有配置task runner,点击配置
选择Others或任一个,弹出默认tasks.json文件,用下面的文件覆盖原来的内容
//tasks.json { "version": "0.1.0", "command": "g++", "args": [ "-g", "${file}", "-o", "${file}.o" ], "problemMatcher": { "owner": "cpp", "fileLocation": [ "relative", "${workspaceRoot}" ], "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 } } }
command: gcc , g++
args: 编译参数
最后再次点调试按钮,即可成功运行调试,可以添加断点,查看变量,堆栈等常用调试功能
相关文章推荐
- Windows下开发、调试Linux C/C++程序
- Windows 下使用Eclipse CDT 远程调试 Linux C/C++ 程序
- Windows 下使用Eclipse CDT 远程调试 Linux C/C++ 程序
- 在Windows下用eclipse编辑/调试Linux C/C++程序
- C++程序调试输出并写入文件(Linux/Windows)
- Windows 下使用Eclipse CDT 远程调试 Linux C/C++ 程序
- 在Windows上用Eclipse远程调试Linux下的C++程序
- Windows 下使用Eclipse CDT 远程调试 Linux C/C++ 程序
- 关于c++检测内存泄露相关知识(windows程序调试)
- linux调试C++错误: 程序中有游离的‘\240’‘\302’
- Windows下Debug Linux C/C++程序的一种方法
- 调试程序时在不中断程序的情况下输出函数调用信息(Mac OS,Linux & Windows)
- linux(Ubuntu)下安装Eclipse 使用CDT调试C/C++程序
- windows下调试linux程序
- Windows程序调试----第一部分 调试策略----第2章 编写使于调试的C++代码
- 【Linux C调试笔记】Linux系统下借助mcheck实现c/c++程序的堆内存异常检查
- 关于c++检测内存泄露相关知识(windows程序调试)
- [待总结]软件移植:C++程序从windows移植到linux
- linux调试C++错误: 程序中有游离的‘\240’‘\302’
- linux 下 gdb 调试c/c++ 程序