Check in online circle did not find what I want, I toss some success, hereby recorded for your reference.
vscode download and installation is very simple, clever as you will see. This article focuses on how to use vscode within the same freedom to switch a c ++ project using the Microsoft msvc cl.exe and MingW of g ++. Exe compiler to compile debugging, to facilitate the learning differences of different compilers. I only had these two compilers, compiler may set up other similar methods.
The net effect:
This is the source of all other files a cpp file hello.cpp and two compilers are compiled after the, hello.cpp content is not important, I learned cpp little practice. . .
It is used to compile cl.exe effect of
this is the same project with g ++. Exe compiler effect
Operation points:
0. The basic premise is that you have a computer cl.exe (vs2019 own or earlier), g ++ exe (codeblocks comes, devcpp own, or download MingW install itself).
1. Due to the complex nature of cl, every time you open c ++ project must be edited vs Used with commands code 项目文件夹
to open vscode, as
if not so open, you may not use cl compiler, g ++ are not affected.
2. Modify your c ++ project tasks.json and launch.json, respectively, add the appropriate codes:
tasks.json:
{
"tasks": [
{ // 对应cl.exe
"type": "shell",
"label": "cl.exe build active file",
"command": "cl.exe",
"args": [ // cl的编译选项,自行设置
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
},
{ // 对应g++.exe
"type": "shell",
"label": "g++.exe build active file",
"command": "D:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin\\g++.exe",
"args": [ // g++的编译选项,自行设置
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-std=c++11",
"-Wall",
"-Weffc++",
"-Wextra",
"-pedantic"
],
"options": {
"cwd": "D:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin" // 换成你自己的相应路径
}
}
],
"version": "2.0.0"
}
launch.json:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{ // 对应cl.exe
"name": "cl.exe build and debug active file",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "cl.exe build active file"
},
{ // 对应g++.exe
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\Program Files (x86)\\CodeBlocks\\MinGW\\gdb32\\bin\\gdb32.exe", // 换成你自己的gdb32.exe的路径
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
After the above two documents were preserved, vscode compilation debug bar appears appropriate compiler configuration:
Summary of procedures:
1. Point 2 is required to modify the operation and good tasks.json launch.json
2. required by the opening operation points 1 VSCode
3. cl any switching or compiled g ++ c ++ debugger program
This is my first blog, I hope this can help you