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前

运行效果:

相关推荐
newobut4 小时前
vscode远程调试python程序,基于debugpy库
vscode·python·调试·debugpy
南棱笑笑生4 小时前
20251211给飞凌OK3588-C开发板适配Rockchip原厂的Buildroot【linux-6.1】系统时适配OV5645摄像头
windows·rockchip
潮流coder7 小时前
vscode修改缓存保存路径
ide·vscode·缓存
承接电子控制相关项目8 小时前
安装VSCODE发现 右击选项中无VSCODE 打开选项,处理方法汇总
ide·vscode·编辑器
Better Bench10 小时前
Ubuntu aarch64\arm64系统安装vscode
linux·vscode·ubuntu
x10n910 小时前
OceanBase 参数对比工具 附源码
数据库·vscode·oceanbase·腾讯云ai代码助手
我是菜鸟0713号11 小时前
VSCode配置Qt6开发教程
ide·vscode·编辑器
老王头的笔记12 小时前
Spring支持的消费器模式,支持在当前事务提交、或回滚的前、后执行业务操作
java·windows·spring
测试人社区-千羽13 小时前
智能测试的终极形态:从自动化到自主化的范式变革
运维·人工智能·python·opencv·测试工具·自动化·开源软件
Jovin Giogic13 小时前
简明教程:记录 Ubuntu系统命令行安装TexLive,配置vscode
linux·vscode·ubuntu·latex·texlive