I’m currently trying to setup OpenCV in my c++ project but I cannot get my main.cpp file to recognize the OpenCV directory. This is my file structure:
IllusionEngine/
│
├─ build/
│
├─ src/
│ ├── images/
│ │ └── chair1.png
│ └── main.cpp
│
└── CMakeLists.txt
When saving my CMakeLists.txt file, CMake finds the OpenCV directory and adds it to the build file:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.29.3)
project(IllusionEngine VERSION 0.1.0)
include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(IllusionEngine src/main.cpp)
target_link_libraries(IllusionEngine ${OpenCV_LIBS})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
Output:
[cmake] -- Found OpenCV: C:/opencv/build (found version "4.9.0")
[cmake] -- Configuring done (2.3s)
[cmake] -- Generating done (0.1s)
[cmake] -- Build files have been written to: C:/Users/arhub/OneDrive/Documents/WIP-AydenHubenak/IllusionEngine/build
However, when attempting to run I get:
c:UsersarhubOneDriveDocumentsWIP-AydenHubenakIllusionEnginesrcmain.cpp:1:10: fatal error: opencv2/opencv.hpp: No such file or directory
1 | #include <opencv2/opencv.hpp>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
I’m not sure exactly where I went wrong. I’ve setup all the correct environment variables beforehand and have followed the available tutorials I can find pretty much word for word. It’s been a few years since I touched c++ so I apologies if this is a simple question. Any help would be greatly appreciated!