CMake fails to add the include directories.

Hi guys,

In Linux I always write Makefiles by hand since it is way easier. I gave cmake it a try in Windows, and here is the result:

I added

add_library(opencv_world451d STATIC IMPORTED)
set_property(TARGET opencv_world451d PROPERTY IMPORTED_LOCATION “C:\opt\opencv\build\x64\vc15\lib”)
target_include_directories( opencv_world451d “C:\opt\opencv\build\include”)

in code I have

#include “opencv2/core.hpp”

and the result is:

|Error (active)|E1696|cannot open source file “opencv2/core.hpp”|CMakeProject1.exe

I tried also using the simpler version

include_directories( “C:\opt\opencv\build\include”)

I tried with and without quotes etc… The result is always the same. So frustrating…
Any idea ?

This is normally a filepath and not a directory. You also want this to be the .dll and IMPORTED_IMPLIB to be the .lib file.

You’re missing an INTERFACE here.

Also, I would recommend using / rather than Windows \ separators as the latter are escape characters in CMake strings, so you need \\ in the CMake source for that to work.

Hi Ben,
Thank you for your reply.
So, I modified it to:

add_library(opencv_world451d STATIC IMPORTED)
set_property(TARGET opencv_world451d PROPERTY IMPORTED_IMPLIB “C:/opt/opencv/build/x64/vc15/lib/opencv_world451d.lib”)
target_include_directories( opencv_world451d INTERFACE “C:/opt/opencv/build/include”)

still can not find the includes. The VS output tab is of no help since there seems to not pass paths to ninja as a command line. Any idea what is still wrong? Any hint to get some debugging info from cmake ? Tnx.

You could set INTERFACE_INCLUDE_DIRECTORIES directly though I’d have expected the target_include_directories to work.