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前

运行效果:

相关推荐
CAE虚拟与现实28 分钟前
VSCode创建Python项目和运行py文件
ide·vscode·编辑器
山烛35 分钟前
OpenCV:图像透视变换
人工智能·opencv·计算机视觉·图像透视变换
csdn_aspnet38 分钟前
Windows Node.js 安装及环境配置详细教程
windows·node.js
摇滚侠1 小时前
java语言中,list<String>转成字符串,逗号分割;List<Integer>转字符串,逗号分割
java·windows·list
Source.Liu1 小时前
【Pywinauto库】12.2 pywinauto.element_info 后端内部实施模块
windows·python·自动化
Source.Liu1 小时前
【Pywinauto库】12.1 pywinauto.backend 后端内部实施模块
开发语言·windows·python·自动化
私人珍藏库2 小时前
[Windows] FileOptimizer v17.1.0_一款文件批量压缩工具
windows·批量压缩
掘根2 小时前
【CMake】List
windows·microsoft·list
Stardep2 小时前
ssh远程连接服务器到vscode上“连接失败”
服务器·vscode·ssh
TToolss4 小时前
删除文件夹里的网盘图标
windows