0

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?

Hairo
  • 11
  • 2
  • In none of you attempts you **link** with OpenCV libraries. And this is what "unresolved externals" error means. Meanwhile any OpenCV example contains the line which links with OpenCV: `target_link_libraries( ${OpenCV_LIBS})` – Tsyvarev Apr 02 '22 at 11:48
  • @Tsyvarev I had also tried this line, but it stopped me at the , since this C++project is obtained from the JEVT and not come from my own, I don't know what should the is, since the built exe will be EncoderApp, I have tried target_link_libraries(EncoderApp ${OpenCV_LIBS}) but it return 'Cannot specify link libraries for target "EncoderApp" which is not built by the project' In the sample code, I see a line "ADD_EXECUTABLE(${name} ${name}.cpp)" , should I also add this? and with what name? I tried to fill it with the cpp that need opencv and it failed – Hairo Apr 02 '22 at 12:14
  • If you don't know how your project is structured and which target(s) it builds, then ask the one who gave you that project. Otherwise prepare [mcve] which reproduces your problem: small project but with **complete code**, **exact error messages** (included into the question post **as text**, not linked as images), etc. – Tsyvarev Apr 02 '22 at 13:48

0 Answers0