简体   繁体   English

VS Code 无法打开源文件“opencv2/opencv.hpp”

[英]VS Code cannot open source file “opencv2/opencv.hpp”

I am trying to include OpenCV library for my project.我正在尝试为我的项目包含 OpenCV 库。 But VS Code keeps showing me the error:但是 VS Code 不断向我显示错误:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/erenerogullari/Desktop/School/DIP/dip02/main.cpp). 
cannot open the source file 'opencv2/opencv.hpp'.

even though I added it to my include path in 'settings.json'.即使我将它添加到“settings.json”中的包含路径中。

Here is my 'main.cpp' file:这是我的“main.cpp”文件:

#include <opencv2/opencv.hpp> // Error is shown here
#include <stdexcept>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;
using namespace cv;

int main(int argc, char **argv){...}

And my 'setting.json' for C/C++ extension in VS Code:还有我在 VS Code 中用于 C/C++ 扩展的“setting.json”:

{
    "editor.formatOnSave": true,
    "kite.showWelcomeNotificationOnStartup": false,
    "C_Cpp.default.includePath": ["${default}", "/Users/eren/opencv-4.5.0/include/opencv2"]
}

I built the project using CMake Tools for VS Code.我使用 CMake Tools for VS Code 构建了项目。 Here is my 'CMakeLists.txt' file if it's helpful in any way:这是我的“CMakeLists.txt”文件,如果它有任何帮助的话:

cmake_minimum_required(VERSION 3.1)

project( dip2 LANGUAGES CXX )

find_package( OpenCV REQUIRED )


add_library(code 
    Dip2.cpp
    Dip2.h
)

set_target_properties(code PROPERTIES
    CXX_STANDARD 11
    CXX_STANDARD_REQUIRED YES
    CXX_EXTENSIONS NO
)


target_link_libraries(code
    PUBLIC
        ${OpenCV_LIBS}
)

target_include_directories(code PUBLIC ${OpenCV_INCLUDE_DIRS})


add_executable(main 
    main.cpp 
)

set_target_properties(main PROPERTIES
    CXX_STANDARD 11
    CXX_STANDARD_REQUIRED YES
    CXX_EXTENSIONS NO
)

target_link_libraries(main 
    PRIVATE
        code
)

target_include_directories(main PUBLIC ${OpenCV_INCLUDE_DIRS})


add_executable(unit_test 
    unit_test.cpp 
)

set_target_properties(unit_test PROPERTIES
    CXX_STANDARD 11
    CXX_STANDARD_REQUIRED YES
    CXX_EXTENSIONS NO
)

target_link_libraries(unit_test 
    PRIVATE
        code
)

target_include_directories(unit_test PUBLIC ${OpenCV_INCLUDE_DIRS})

I am using Visual Studio Code 1.51.1 on macOS 11.0.1.我在 macOS 11.0.1 上使用 Visual Studio Code 1.51.1。 Thank you in advance!先感谢您!

I was able to solve it by reinstalling OpenCV with homebrew and adding the path to included paths in C/C++ extension:我能够通过使用自制软件重新安装 OpenCV 并将路径添加到 C/C++ 扩展中包含的路径来解决它:

{
"editor.formatOnSave": true,
"kite.showWelcomeNotificationOnStartup": false,
"C_Cpp.default.includePath": [
    "${default}",
    "/usr/local/Cellar/opencv/4.5.0_5/include/opencv4"
]

} }

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

相关问题 无法在 Visual Studio 2019 中打开源文件 opencv2/opencv.hpp - cannot open source file opencv2/opencv.hpp in visual studio 2019 错误C1083无法在VS 2015中打开包含文件:&#39;opencv2 \\ opencv.hpp&#39; - Error C1083 Cannot open include file: 'opencv2\opencv.hpp' in VS 2015 致命错误:opencv2/opencv.hpp:没有这样的文件或目录#include“opencv2/opencv.hpp” - fatal error: opencv2/opencv.hpp: No such file or directory #include "opencv2/opencv.hpp" #包括<opencv2/opencv.hpp>在 VS 2013 中不起作用 - #include <opencv2/opencv.hpp> not working in VS 2013 opencv2 / opencv.hpp:使用Eclipse IDE时没有这样的文件或目录 - opencv2/opencv.hpp: No such file or directory using Eclipse IDE <opencv2/opencv.hpp> ,<opencv2/imgproc.hpp> ,<opencv2/highgui.hpp> 无此文件或目录 - <opencv2/opencv.hpp>, <opencv2/imgproc.hpp>, <opencv2/highgui.hpp> no such file or directory vscode代码static分析时找不到'opencv2/opencv.hpp'文件 - 'opencv2/opencv.hpp' file not found when vscode code static analysis VS2019:致命错误 C1083 无法打开头文件:&#39;opencv.hpp&#39; - VS2019:fatal error C1083 Cannot open header file: 'opencv.hpp' C++ 无法打开源文件“opencv2/tracking.hpp” - C++ cannot open source file "opencv2/tracking.hpp" 简单地包括<opencv2 opencv.hpp>导致链接错误</opencv2> - Simply including <opencv2/opencv.hpp> results in linking error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM