如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033
环境:
OS : winows 7 64bit
MinGW-w64 Version : x86_64-8.1.0-release-win32-seh-rt_v6-rev0
VSCode : 1.37( Electron: 4.2.7 Chrome: 69.0.3497.128 Node.js: 10.11.0 V8: 6.9.427.31-electron.0)
VSCode C++插件:C/C++ for Visual Studio Code 0.25.0-insiders: August 8, 2019
相关文章:
MinGW-w64简介
MinGW-w64在windows下的离线安装
为什么会使用VSCode在windows下调试C++程序呢?windows下不是有Visual Studio吗?
主要因为Visual Studio太重量级了,而且跨平台支持不够完善,因此才有了本文
略过
vs code应用商店所有C/C++,其中Microsoft发布的就是,全名C/C++ for Visual Studio Code
源码:
https://github.com/microsoft/vscode-cpptools
文件命名为hello.cpp
#include
int main()
{
printf("Hello World");
}
c_cpp_properties.json可以配置头文件、编译器、标准等
//c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
配置任务可以自动编译生成.exe
//tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++", //与launch.json的preLaunchTask选项一致
"command": "D:/mingw64/bin/g++.exe",//指定g++
"args": [//设置编译参数
"-g",
"${workspaceFolder}/hello.cpp",
"-o",
"hello.exe"
],
"options": {
"cwd": "D:/mingw64/bin"//指定编译环境位置
},
"problemMatcher": [
"$gcc"
]
}
]
}
通过lauch.json(调试 - 打开配置)来配置启动参数
//lauch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/hello.exe",//修改运行的exe名称
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:/mingw64/bin/gdb.exe",//修改gdb路径
"preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
觉得文章对你有帮助,可以扫描二维码捐赠给博主,谢谢!
如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033
License
License under CC BY-NC-ND 4.0: 署名-非商业使用-禁止演绎
Reference:
1.http://www.mingw-w64.org
2.MinGW-w64简介
3.MinGW-w64在windows下的离线安装