I'm pretty new to using CMake to build/compile OpenCV projects in Visual Studio Code.
From my understanding so far, this is the 'typical' CMake file 'format' if I want to compile a OpenCV project
cmake_minimum_required(VERSION 3.0.0)
project(OpenCV_Hello_World VERSION 0.1.0 LANGUAGES C CXX)
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
# Find OpenCV package
find_package(OpenCV REQUIRED)
# Include OpenCV headers
include_directories(${OpenCV_INCLUDE_DIRS})
# Create the executable
add_executable(OpenCV_Hello_World main.cpp)
# Link OpenCV libraries
target_link_libraries(OpenCV_Hello_World PRIVATE ${OpenCV_LIBS})
In my main directory, I have :
main.cppCMakelists.txtbuildfolder to hold all the files that get generated from the CMake file
With the CMake file listed above, when I use cmake -G "Unix Makefiles" .. and make to build/compile my main.cpp, I get the following error:
CMake Error at E:/Coding Folder/OpenCV Folder/build/win-install/x64/vc16/lib/OpenCVConfig.cmake:290 (get_target_property):
get_target_property() called with non-existent target "opencv_world".
But if I were to specify where my OpenCV lib files are at with the set() command, I'm able to compile/build everything just fine.
Here's the CMake file that I'm currently using
cmake_minimum_required(VERSION 3.0.0)
project(OpenCV_Hello_World VERSION 0.1.0 LANGUAGES C CXX)
# Set the OpenCV directory
#set(OpenCV_DIR " INSERT PATH TO OPENCV LIB HERE ")
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
# Find OpenCV package
find_package(OpenCV REQUIRED)
# Include OpenCV headers
include_directories(${OpenCV_INCLUDE_DIRS})
# Create the executable
add_executable(OpenCV_Hello_World main.cpp)
# Link OpenCV libraries
target_link_libraries(OpenCV_Hello_World PRIVATE ${OpenCV_LIBS})
I was under the heavy impression that the find_package(OpenCV REQUIRED) command would 'find' my OpenCV files and I'm confused on why that's not the case.
<...>/win-install/x64/vc16/lib/OpenCVConfig.cmakedescribes installation of OpenCV for Visual Studio. It is not compatible withUnix Makefilesgenerator, which configures the project for Linux (you run the configure under WSL, don't you?).cmake -G "Unix Makefiles" ..and themakecommand is purely so I don't have tocdinto theReleasefolder if I usedcmake -DCMAKE_BUILD_TYPE=Release ..andcmake --build . --config Releaseto build and compile with my Visual Studio configuration. But to answer your question if I'm "Running the configure under WSL" I'm using aPowershellterminal in Visual Studio Code