use vscode mingw cmake on windows

Remember mingw to go to MingW-W64-builds under the official website and download this version
x86_64-13.1.0-release-posix-seh-ucrt-rt_v11-rev1.7z
posix is very important, the win32 version does not have thread support, and an error will be reported when using it.

You can test whether it can run normally

#include <thread>
#include <mutex>
#include <condition_variable>
#include <iostream>

std::thread second_workthread;
std::mutex mtx;
std::condition_variable objectDetectorRun;

task.json
Anhao mingw, cmake

{<!-- -->
    "version": "2.0.0",
    "windows": {<!-- -->
        "options": {<!-- -->
            "shell": {<!-- -->
                "executable": "powershell"
            }
        }
    },
    "type": "shell",
    "options": {<!-- -->
        "cwd": "${workspaceRoot}"
    },
    "tasks": [
        {<!-- -->
            "label": "cmake",
            "linux": {<!-- -->
                "command": "cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Debug .."
            },
            "windows": {<!-- -->
                "command": "cmake -G 'MinGW Makefiles' .."
            },
            "type": "shell",
            "dependsOn": "_makebuildfolder",
            "options": {<!-- -->
                "cwd": "${workspaceRoot}/build"
            },
            "presentation": {<!-- -->
                "echo": true,
                "reveal": "always",
                "panel": "shared"
            },
            "problemMatcher": [],
            "group": "build"
        },
        {<!-- -->
            "label": "make",
            "linux": {<!-- -->
                "command": "make -j 8"
            },
            "windows": {<!-- -->
                "command": "mingw32-make -j 4"
            },
            "options": {<!-- -->
                "cwd": "${workspaceRoot}/build"
            },
            "presentation": {<!-- -->
                "echo": true,
                "reveal": "always",
                "panel": "shared"
            },
            "isBuildCommand": true,
            "problemMatcher": [],
            "group": "build"
        },
        {<!-- -->
            "label": "_makebuildfolder",
            "type": "shell",
            "linux": {<!-- -->
                "command": "mkdir -p ${workspaceFolder}/build"
            },
            "windows": {<!-- -->
                "command": "mkdir -Force ${workspaceFolder}/build"
            },
            "problemMatcher": [],
            "group": "build"
        },
        {<!-- -->
            "label": "copy_raw",
            "type": "shell",
            "linux": {<!-- -->
                "command": "mkdir -p ${workspaceFolder}/build"
            },
            "windows": {<!-- -->
                "command": "Copy ${workspaceFolder}/*.raw ${workspaceFolder}/build "
            }
        },
        {<!-- -->
            "label": "run",
            "args": ["32"],
            "windows": {<!-- -->
                "command": "${command:cmake.launchTargetPath}"
            },
            "options": {<!-- -->
                "cwd": "${workspaceRoot}/build"
            },
        },
        {<!-- -->
            "label": "runwithbuild",
            "args": ["32"],
            "windows": {<!-- -->
                "command": "${command:cmake.launchTargetPath}"
            },
            "dependsOrder": "sequence", //tj : make sure exe deps in order
            "dependsOn": ["cmake", "make", "copy_raw"],
            "options": {<!-- -->
                "cwd": "${workspaceRoot}/build"
            },
        }
    ]
}

For opencv, you can either compile it yourself with Mingw, or download the existing one. I downloaded the ready-made one here https://github.com/huihut/OpenCV-MinGW-Build

cmake_minimum_required(VERSION 3.5)
project(main)

set(CMAKE_CXX_FLAGS "-std=c + + 14")
set (OpenCV_DIR C:\Software\OpenCV-MinGW-Build)
find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})


add_executable(main main.cpp)
target_link_libraries( main ${Pangolin_LIBRARIES} )

If debug

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",
            "request": "launch",
            "targetArchitecture": "x86",
            "program": "${command:cmake.launchTargetPath}",
            // "program": "${workspaceFolder}/build/main.exe",
            // "program": "${fileDirname}\${fileBasenameNoExtension}.exe",
            "args": ["32"],//Start debug on the left, pick up args from here
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/build",
            "environment": [
                {<!-- -->
                    "name": "PATH",
                    "value": "${env:Path};C:\Workspace\v-nova\build"
                    //The setting here is wrong, and it is easy to cause Unable to start debugging. Unexpected GDB output from command “-exec-run”
                }
            ],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/Software/mingw64/bin/gdb.exe",
            "setupCommands": [
                {<!-- -->
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
        }
    ]
}

Need to configure cmake:configure with cmake debugger

Pay attention to the status bar at the bottom. If there is no setting, click to set it.
In addition, cmake may allow

C:\Software\OpenCV-MinGW-Build\x64\mingw\bin

Add environment variables

If passing parameters in launch.json does not work, add it in setting.json

If you start debugging from the status bar, set args in setting.json

{<!-- -->
    "cmake.configureOnOpen": false,
    "files.associations": {<!-- -->
        "ostream": "cpp",
        "mutex": "cpp",
        "array": "cpp",
        "string": "cpp",
        "string_view": "cpp"
    },
    "C_Cpp.default.compilerPath": "C:\Software\mingw64\bin\g + + .exe",
    "cmake.debugConfig": {<!-- -->
        "args": [
            "32"//Start debug below and pick up args from here.
        ]
    }
}

If you start debug from the left, args are set in launch.json

https://github.com/microsoft/vscode-cmake-tools/issues/121