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 } ] } ] }
参考
https://code.visualstudio.com/docs/cpp/config-mingw
https://www.cnblogs.com/baihualiaoluan/p/10661669.html