vscode c++ opencv_mingw配置
1.安装msys2
Get the latest version of MinGW-w64 via MSYS2, which provides up-to-date native builds of GCC, MinGW-w64, and other helpful C++ tools and libraries. This will provide you with the necessary tools to compile your code, debug it, and configure it to work with IntelliSense.
2.安装mingw-w64 安装opencv-mingw-build
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
https://github.com/huihut/OpenCV-MinGW-Build
3.vscode 新建工作文件夹,新建 hello.cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
4.配置task.json -> Run c/c++ file
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"-fexec-charset=GBK", //中文乱码
"${workspaceFolder}/*.cpp", //编译所有cpp文件
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
// -I 头文件目录
// -L 库文件目录
// -l 库文件
"-I","D:/opencv/install/include",
"-I","D:/opencv/install/include/opencv2",
"-L","D:/opencv/install/x64/mingw/lib",
"-l","libopencv_video450"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
5.配置launch.json
To create launch.json, choose Add Debug Configuration from the play button drop-down menu.
{
"configurations": [
{
"name": "C/C++: g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true, //外部终端
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
],
"version": "2.0.0"
}
6.c++ setting (ui)
{
"configurations": [
{
"name": "GCC",
"includePath": [
"${workspaceFolder}/**",
"D:/opencv/install/include",
"D:/opencv/install/include/opencv2" //头文件路径
],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"windowsSdkVersion": "10.0.22000.0",
"compilerPath": "C:/msys64/mingw64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}