windows10 mingw + vscode
基本上按照官方的教程页就没问题, 以下有几个可以小优化的地方.
1, 文件名
- ${
- file
- },${
- fileBasenameNoExtension
- }.exe
- hello.cpp >> hello.exe
- 2,"preLaunchTask" in launch
- first in task.JSON : "label": "g++ build active file"
- then in launch.JSON "preLaunchTask": "g++ build active file"
再 .vscode 中至少配置 3 个文件
- c_cpp_properties.JSON
- tasks.JSON
- launch.JSON
- c_cpp_properties.JSON
- {
- "configurations": [
- {
- "name": "g++",
- "includePath": [
- "${workspaceFolder}/**"
- ],
- "defines": [
- "_DEBUG",
- "UNICODE",
- "_UNICODE"
- ],
- "windowsSdkVersion": "10.0.17763.0",
- "compilerPath": "D:/mingw64/bin/g++.exe", // mingw 配置目录
- "cStandard": "c11",
- "cppStandard": "c++17",
- "intelliSenseMode": "${default}"
- }
- ],
- "version": 4
- }
- tasks.JSON
- {
- // 有关 tasks.JSON 格式的文档, 请参见
- // https://go.microsoft.com/fwlink/?LinkId=733558
- "version": "2.0.0",
- "tasks": [
- {
- "type": "shell",
- "label": "g++ build active file", //taskname, 在 launch.JSON 中可以配置给 prelaunch
- "command": "g++",
- "args": [
- "-g",
- "${file}",
- "-o",
- "${fileBasenameNoExtension}.exe"
- ],
- "group": {
- "kind": "build",
- "isDefault": true
- }
- }
- ]
- }
- 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": "(gdb) Launch", // 配置名称, 将会在启动配置的下拉菜单中显示
- "type": "cppdbg", // 配置类型, 这里只能为 cppdbg
- "request": "launch", // 请求配置类型, 可以为 launch(启动) 或 attach(附加)
- "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径
- "args": [], // 程序调试时传递给程序的命令行参数, 一般设为空即可
- "stopAtEntry": false, // 设为 true 时程序将暂停在程序入口处, 一般设置为 false
- "cwd": "${workspaceFolder}", // 调试程序时的工作目录, 一般为 ${workspaceRoot} 即代码所在目录
- "environment": [],
- "externalConsole": true, // 调试时是否显示控制台窗口, 一般设置为 true 显示控制台
- "MIMode": "gdb",
- "miDebuggerPath": "D:/mingw64/bin/gdb.exe", // miDebugger 的路径, 注意这里要与 MinGw 的路径对应
- "preLaunchTask": "g++ build active file", // 调试会话开始前执行的任务, 一般为编译程序, c++ 为 g++, c 为 gcc
- "setupCommands": [
- {
- "description": "Enable pretty-printing for gdb",
- "text": "-enable-pretty-printing",
- "ignoreFailures": true
- }
- ]
- }
- ]
- }
参考
来源: http://www.bubuko.com/infodetail-3260906.html