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前

运行效果:

相关推荐
怜渠客8 分钟前
【原创工具】Excel像素画生成 By怜渠客
windows·实用工具·怜渠客
weixin_4896900218 分钟前
MicroSIP自定义web拨打协议
服务器·前端·windows
yuanmenghao19 分钟前
Linux 配置Samba,Windows登录,开机自动映射登录
linux·运维·windows·操作系统·samba
晴天飛 雪38 分钟前
Spring Boot 接口耗时统计
前端·windows·spring boot
Jackson@ML1 小时前
2026最新版Visual Studio Code安装使用指南
ide·vscode·编辑器
狂放不羁霸1 小时前
Tailscale | 校园网外笔记本借助校园网内主机连接实验室服务器
运维·服务器·vscode
凡客丶1 小时前
Windows版Miniconda打包环境迁移到内网离线环境【详解】
windows·python
小-黯1 小时前
QT编译MySQL驱动教程(Windows/Linux)
windows·qt·mysql
数智工坊1 小时前
【操作系统-处理器调度】
java·linux·服务器·windows·ubuntu
amazing-yuan2 小时前
Windows系统查看是否已安装Mysql,查找Mysql的安装地址,忘记root账号的密码时重置密码操作指引
数据库·windows·mysql