首页 > 解决方案 > 使用 Visual Studio Code 调试 C++,包括 Linux 中的 OpenCV

问题描述

我按照本教程在我的 Linux 中安装 OpenCV。

然后我按照另一个教程创建了 CMakeLists.txt。它看起来像这样:

cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

然后我在终端中键入cmake CMakeLists.txt以创建 Makefile 文件以最终执行make以运行程序。

显然,我的程序包括opencv2/opencv.hpp。

当我尝试调试它时,问题就来了。我尝试包含所有库,但仍然有问题,因此无法调试。我的 tasks.json 如下:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-I${fileDirname}/build",
                "-I${fileDirname}/opencv-master/include",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"

            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

然后我得到类似的错误:fatal error: opencv2/core.hpp: No such file or directory,如果我尝试将所有这些 .hpp 包含在 tasks.json 中,我会得到类似的错误undefined reference to `cv::Mat::Mat(),所以我不知道我该怎么做才能在 Visual Studio Code 中调试我的 c++ 文件。

我想我应该以某种方式将我的 Makefile 传递给 tasks.json,但我不知道我该怎么做。

谢谢。

标签: c++opencvdebuggingvisual-studio-codecmake

解决方案


推荐阅读