c++ - 如何修复由于 C++ includePath 导致的 "No such file or directory..."错误

标签 c++ opencv visual-studio-code include-path

我试图在我的代码中包含多个 hpp 文件,但是我的 c_cpp_properties.json 中的包含路径选项似乎无法正常工作。我一直收到“没有这样的文件或目录...”,即使那里有正确的文件。

我已将路径添加到 c_cpp_properties.json 文件的 includePath 部分,但它仍然找不到文件。

包含主文件的一部分:

#include <iostream>
#include<conio.h>
#include <D:\OpenCV\opencv\build\include\opencv2\core\core.hpp>
#include <D:\OpenCV\opencv\build\include\opencv2\highgui.hpp>
#include <D:\OpenCV\opencv\build\include\opencv2\imgproc\imgproc.hpp>

c_cpp_properties.json 文件:

    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "D:/OpenCV/opencv/build/include",
                "D:/OpenCV/opencv/sources/modules/core/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}```

The file should run, but this error is causing it not to.

最佳答案

如果 c_cpp_properties.json 包含编译时使用的属性,您的 #include 应该看起来像这样:

#include <iostream>
#include <conio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include 中的单个反斜杠很可能被解释为 escape sequences 的开始这不会导致正确的路径。

关于c++ - 如何修复由于 C++ includePath 导致的 "No such file or directory..."错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56527724/

相关文章:

vim - 如何在 Visual Studio Code vim 扩展中使用 vim(键绑定(bind))

c++ - 何时调用 QApplication 析构函数

c++ - 如何防止将 `#warning` 消息视为错误?

c++ - RAII理解——有界指针的访问方法

matlab - 从线的交点查找两个不同对象之间的角度

visual-studio-code - VS Code,如何从 editor.formatOnSave 中排除目录

一个项目中的 C++14 和 C++17

opencv - 链接 : fatal error LNK1104: cannot open file '.obj'

c++ - 用于 cv::Mat 参数的 OpenCV std::vector

python - 带有 Jupyter Notebook : Shortcut for “run all” ? 的 Visual Studio 代码