I am a student working on a video encoder VTM-14.0 with some opencv libraries in Visual Studio 2019. I tried to use some opencv method by including the opencv in the project. According to some tutorials, I have download the opencv, set the path into environment variables.
I have included
#include <opencv/core.hpp>
#include <opencv/opencv.hpp>
#include <opencv/dnn/dnn.hpp>
#include <opencv/mat.hpp>
And visual studio just gave me some error
cannot open source file "opencv2/core.hpp"
cannot open source file "opencv2/opencvhpp"
cannot open source file "opencv2/dnn/dnn.hpp"
cannot open source file "opencv2/mat.hpp"
I search over the internet and tried many solution like Project->Properties->Configuration Properties->C/C++->General->Additional Include Directories But I my case, there is no properties tab, there are only Cmake settings. I even tried right click the project folder and click properties and it return a empty properties tab.
I assume this is a different situation since the project(VTM-14.0) is built with Cmake, so I go for the direction about cmake.
In some sample code of opencv, I find that the CMakeList.txt contain these code
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS})
I added them and save. The complier does not show any error for the #include tab. But when I tried building the solution (with x64-Release), multiple unresolved external symbol error shown.
Afterward, I have tried
set(OpenCV_ROOT "path that contain include and x64")
set(OpenCV_INCLUDE_DIR "{$OpenCV_ROOT}/include")
set(OpenCV_LIBRARY_DIR "{$OpenCV_ROOT}/x64/vc16/lib")
I also tried downloading other opencv packages like opencv-4.2.0, opencv-4.5.5. They does not work, so I think that I should use the library with x64/vc16/lib (I don't know why the above rebuilded version downloaded from https://opencv.org/releases/ only have vc14 and vc15).
So I also tried to download 4.2.0 source, build it with cmake-gui(with Visual Studio 2019 and x64 config), build the ALL_BUILD project and INSTALL project and try the opencv-4.2.0/build/install as root path again.
All of above result in either cannot open source file "The hpp files" or unresolved external symbol after building.
Many of the solution also mentioned abouttarget_link_libraries(<your executable> ${OpenCV_LIBS})
, I also tried it but I don't know what should be the since this project is not defined by me. I know the exe file will be EncoderApp.exe but I just get another error after adding target_link_libraries(EncoderApp ${OpenCV_LIBS})
And other try like this does not work also (encmain.cpp is the main)
add_executable(main encmain.cpp)
target_link_libraries(main ${OpenCV_LIBS})
Does any one know what should I try to fix the problem or any step I may have done wrong?