简体   繁体   English

VSCode C++ IntelliSense/自动完成功能不适用于 OpenCV C++

[英]VSCode C++ IntelliSense/autocomplete is not working for OpenCV C++

OpenCV is installed from the source on my Linux (Ubuntu 18.04.6 LTS) machine. OpenCV 从源代码安装在我的 Linux(Ubuntu 18.04.6 LTS)机器上。 The path is a bit different ie /usr/local/<blah_blah> and the directory tree looks somewhat like this:路径有点不同,即/usr/local/<blah_blah>目录树看起来有点像这样:

milan@my_machine:/usr/local/<blah_blah>$ tree -L 4
.
├── bin
│   ├── opencv_annotation
│   └── ...
├── include
│   └── opencv4
│       └── opencv2
│           ├── ...
│           ├── core
│           ├── core.hpp
│           ├── ...
│           └── ...
├── lib
│   ├── cmake
│   │   └── opencv4
│   │       ├── OpenCVConfig.cmake
│   │       └── ...
│   ├── ...
│   ├── libopencv_core.so -> libopencv_core.so.4.2
│   ├── libopencv_core.so.4.2 -> libopencv_core.so.4.2.0
│   ├── libopencv_core.so.4.2.0
│   ├── ...
│   ├── ...
│   ├── opencv4
│   │   └── 3rdparty
│   │       ├── ...
│   │       └── ...
│   ├── python2.7
│   │   └── dist-packages
│   │       └── cv2
│   └── python3.6
│       └── dist-packages
│           └── cv2
└── share
    ├── licenses
    │   └── opencv4
    │       ├── ...
    │       └── ...
    └── opencv4
        ├── ...
        │   └── ...
        ├── ...
        └── ...

I had a similar issue for PCL (Point Cloud Library) in the past and my answer/solution fixed that.过去我对 PCL(点云库)有类似的问题我的答案/解决方案解决了这个问题。 So, I tried something similar:所以,我尝试了类似的东西:

In settings.json , I put:settings.json ,我输入:

    "C_Cpp.default.includePath": [
        "/usr/local/<blah_blah>/include/opencv4/opencv2/**",
        "/usr/local/<blah_blah>/include/opencv4/opencv2/core",
        "/usr/local/<blah_blah>/include/opencv4/opencv2/core/*",
        "/usr/local/<blah_blah>/include/opencv4/opencv2/core/**"
    ],

and in the c_cpp_properties.json file, I put:c_cpp_properties.json文件中,我输入:

            "includePath": [
                "${workspaceFolder}/**",
                "${default}"
            ],

However, doing this is not fixing the issue.但是,这样做并不能解决问题。 C++ IntelliSense/autocomplete still does not work for OpenCV C++. C++ IntelliSense/自动完成功能仍然不适用于 OpenCV C++。 So, how to fix this issue?那么,如何解决这个问题呢?

Sample Code:示例代码:

示例代码

Note1:注1:

  • In cmake , /usr/local/<blah_blah>/include/opencv4 is used under include_directories .cmake中, /usr/local/<blah_blah>/include/opencv4include_directories下使用。
  • Compilation and execution work fine.编译和执行工作正常。

Note2: the following questions/issues are different from mine:注2:以下问题/问题与我的不同:

  1. VSCode autocomplete not working for OpenCV installed from source -- for OpenCV Python, not C++ VSCode 自动完成不适用于从源安装的 OpenCV - 对于 OpenCV Python,而不是 ZF130987C9FDCFEE873
  2. cv2 (opencv-python) intellisense not working -- for OpenCV Python, not C++ cv2(opencv-python)intellisense 不工作——对于 OpenCV Python,不是 C++

It turned out that in my settings.json file, the includePath s were set like this:原来,在我的settings.json文件中, includePath是这样设置的:

"C_Cpp.default.includePath": [
        "/usr/local/<blah_blah>/include/opencv4/opencv2/**",
        "/usr/local/<blah_blah>/include/opencv4/opencv2/core.hpp",
        "/usr/local/<blah_blah>/include/opencv4/opencv2/core",
        .
        .
],

However, in my code, the headers were included like:但是,在我的代码中,标题包括:

#include <opencv2/core.hpp>

If the opencv2 folder needs to be included in the #include directive, the includePath s should look like this:如果opencv2文件夹需要包含在#include指令中,则includePath应如下所示:

"C_Cpp.default.includePath": [
        "/usr/local/<blah_blah>/include/opencv4",
        .
        .
],

So, the following includePath s configuration fixed the issue with IntelliSense/autocompletion for OpenCV :因此,以下includePath配置修复了OpenCV的 IntelliSense/自动完成问题:

"C_Cpp.default.includePath": [
        "/usr/local/<blah_blah>/include/opencv4",
        "/usr/local/<blah_blah>/include/opencv4/**",
],

For a detailed explanation, take a look into the issue ( Issue 9900 ) I created on vscode-cpptools GitHub page, particularly this thread/reply .有关详细说明,请查看我在vscode-cpptools GitHub 页面上创建的问题(问题 9900 ),尤其是此线程/回复

Special thanks to vscode-cpptools and vscode-cmake-tools team!特别感谢vscode-cpptoolsvscode-cmake-tools团队!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM