I am very new to C++ and cmake (that means: I started yesterday) and I am stuck trying to include OpenCV. It might be a complete rookie mistake that I made somewhere during installation as well, so I am really hoping for your ideas and experience. So, this is the code I am trying to run:
#include <opencv2/opencv.hpp>
#include <iostream>
int main(){
std::cout << CV_VERSION << std::endl;
return 0;
}
This is the error message I am getting:
main.cpp:1:30: fatal error: opencv2/opencv.hpp: No such file or directory
#include <opencv2/opencv.hpp>
I had a look at this post here and updated my CMake file to this:
cmake_minimum_required(VERSION 3.0.0)
project(myproject VERSION 0.1.0 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)
include(CTest)
enable_testing()
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
message("OpenCV_INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}")
add_executable(myproject main.cpp)
target_link_libraries(myproject ${OpenCV_LIBS} )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
UPDATE: Meanwhile, I added a couple of json
files, as suggested here.But I am not exactely sure if I adjusted them correctly to my case.
So this is my c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:/opencv/sources/include",
"C:/opencv/build/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/msys64/mingw64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
But that didn't solve the problem either. Any ideas on what is wrong? As I said, I am completely new to this so it might be something really easy/stupid. ^^°
Those are the locations on my PC where Cmake and openCV are stored, in case that is relevant :
C:\opencv
C:\Program Files\CMake