[英]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.