Windows环境VSCode配置OpenCV-项目配置(二)

  1. 修改c_cpp_properties.json

    复制代码
     {
      "configurations": [
        {
          "name": "windows-gcc-x64",
          "includePath": [
            "${workspaceFolder}/**",
            "D:/mingw64/mingw64/include",
            "D:/openCV_win/build/install/include",
            "D:/openCV_win/build/install/include/opencv2"
          ],
          "compilerPath": "D:/mingw64/mingw64/bin/gcc.exe",
          "cStandard": "${default}",
          "cppStandard": "${default}",
          "intelliSenseMode": "windows-gcc-x64",
          "compilerArgs": [
            ""
          ]
        }
      ],
      "version": 4
    }
  2. 修改tasks.json

    复制代码
    {
        "tasks": [
            {
                "type": "cppbuild",
                "label": "C/C++: g++.exe 生成活动文件",
                "command": "D:\\mingw64\\mingw64\\bin\\g++.exe",
                "args": [
                    "-fdiagnostics-color=always",
                    "-g",
                    "${file}",
                    "-o",
                    "${fileDirname}\\${fileBasenameNoExtension}.exe",
                    "-I", "D:/openCV_win/build/install/include/",
                    "-I", "D:/openCV_win/build/install/include/opencv2/",
                    "-L", "D:/openCV_win/build/install/x64/mingw/bin/lib*"
                ],
                "options": {
                    "cwd": "${fileDirname}"
                },
                "problemMatcher": [
                    "$gcc"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "detail": "调试器生成的任务。"
            }
        ],
        "version": "2.0.0"
    }
  3. launch.json

    复制代码
    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "C/C++ Runner: Debug Session",
          "type": "cppdbg",
          "request": "launch",
          "args": [],
          "stopAtEntry": false,
          "externalConsole": true,
          "cwd": "${workspaceFolder}",
          "program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
          "MIMode": "gdb",
          "miDebuggerPath": "gdb",
          "setupCommands": [
            {
              "description": "Enable pretty-printing for gdb",
              "text": "-enable-pretty-printing",
              "ignoreFailures": true
            }
          ]
        }
      ]
    }
  4. 新建test.cpp

    复制代码
     #include <iostream>
    #include <opencv2/opencv.hpp>
    using namespace std;
    
    int main() {
        std::cout << "Hello, World start" << std::endl;
        cv::Mat img = cv::imread("C:/Users/Pictures/nba/724224.jpg");
        cv::imshow("img", img);
        cv::waitKey(0);
        std::cout << "Hello, World end" << std::endl;
        return 0;
    }

如果F5出错

Unexpected GDB output from command "-exec-run".

需要修改mingw64的环境变量到git前

运行效果:

相关推荐
jingshaoqi_ccc1 小时前
windows 10系统下QT的安装及在Visual studio中的扩展安装
windows·qt·visual studio
東雪木6 小时前
泛型、反射、注解(Spring 框架核心底层)专属复习笔记
java·windows·笔记·学习·spring
sun0077008 小时前
Windows下UniGetUI,Linux下敲命令
windows
流星白龙8 小时前
【MySQL高阶】18.缓冲池页管理
数据库·windows·mysql
AI行业学习9 小时前
PuTTY 工具下载部署、基础配置及 SSH 远程服务器连接完整操作指南Windows 平台 【2026.6.1】
运维·windows·ssh
tealcwu9 小时前
【Unity实战】Unity IAP 4.x 在 Windows Store (UWP) 平台上的实现指南
windows·unity·游戏引擎
小铁-Android10 小时前
Visual Studio Code创建Flutter项目时包名组织名更改
vscode·flutter
爱讲故事的11 小时前
操作系统第四讲:OS Interfaces and Syscalls(操作系统接口与系统调用)
linux·windows·ubuntu
糖果店的幽灵11 小时前
LangChain 1.3 完全教程:从入门到精通-Part 10: Memory(记忆系统)
windows·microsoft·langchain
半壶清水12 小时前
PaddlePaddle、easyocr与OpenCV工具识别书法图片内容,自动批量重命名图片文件的方法
人工智能·opencv·ocr·paddlepaddle