Visual Studio Code 配置C/C++编译及调试环境
Windows下VSCode配置C++环境
VSCode配置C++官方文档
Get Started with C++ on Linux in Visual Studio Code
VSCode下载
点击左侧栏第五个,在搜索框内输入【c++】,安装c++插件。
c_cpp_properties.json
文件Ctrl+Shift+P调出命令面板
==》输入C/C++,选择【Edit Configurations(UI)】进入配置
==》在.vscode文件夹中自动生成 c_cpp_properties.json 文件
修改配置:
D:/360Downloads/Software/MinGW/mingw64/bin/bin/g++.exe
;gcc-x64
;#include
using namespace std;
int main()
{
cout << "hello world!" <
task.json
文件task.json
文件,代码进行编译的配置文件。
选择 【Terminal】
==》【configure task】
==》【C/C++:g++.exe生成活动文件】
shift+ctrl+B
执行编译,生成 demo.exe
文件。
按 ctrl+F5
,运行 demo.exe
。
launch.json
文件launch.json
文件,代码进行调试(debug)的配置文件。
选择 【Run】
==》【Add Configuration
==》【C++(GDB/LLDB)】
==》【g++.exe - 生成和调试活动文件】
demo.exe
按 F5
,调试 demo.exe
。
或者
Run
==》Start Debugging
task.json
和 launch.json
文件之前,务必切换到 demo.cpp
或者 demo.c
文件,否则自动生成的 task.json
和 launch.json
无法编译对应的 demo.cpp
和 demo.c
。.vscode
文件夹备份一份,以后需要的时候直接复制即可,不用再花时间进行配置了。c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:\\360Downloads\\Software\\opencv\\build\\x64\\MinGw\\install\\include",
"D:\\360Downloads\\Software\\opencv\\build\\x64\\MinGw\\install\\include\\opencv2"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/360Downloads/Software/MinGW/mingw64/bin/g++.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\360Downloads\\Software\\MinGW\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I", "D:\\360Downloads\\Software\\opencv\\build\\x64\\MinGw\\install\\include",
"-I", "D:\\360Downloads\\Software\\opencv\\build\\x64\\MinGw\\install\\include\\opencv2",
"-L", "D:\\360Downloads\\Software\\opencv\\build\\x64\\MinGw\\lib",
"-l", "libopencv_calib3d452",
"-l", "libopencv_core452",
"-l", "libopencv_dnn452",
"-l", "libopencv_features2d452",
"-l", "libopencv_flann452",
"-l", "libopencv_gapi452",
"-l", "libopencv_highgui452",
"-l", "libopencv_imgcodecs452",
"-l", "libopencv_imgproc452",
"-l", "libopencv_ml452",
"-l", "libopencv_objdetect452",
"-l", "libopencv_photo452",
"-l", "libopencv_stitching452",
"-l", "libopencv_video452",
"-l", "libopencv_videoio452"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: D:\\360Downloads\\Software\\MinGW\\mingw64\\bin\\g++.exe"
}
]
}
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": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\360Downloads\\Software\\MinGW\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe 生成活动文件"
}
]
}