microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.28k stars 6.43k forks source link

Cannot open include file: 'opencv2/opencv.hpp': No such file or directory #2115

Closed chuong closed 5 years ago

chuong commented 7 years ago

I'm using Windows 10 Anniversary and OpenCV was successfully installed with .\vcpkg install opencv.

I got the above error although everything seems to work well until I run build solution on Visual Studio Community 2017.

main.cpp created as:

#include <opencv/cv.hpp>

int main()
{
    cv::Mat im = cv::Mat::zeros(cv::Size(640, 480), CV_8UC3);
    cv::imshow("test", im);
    cv::waitKey(0);
}

CMakeLists.txt is:

cmake_minimum_required(VERSION 3.0)
project(test)

find_package(opencv REQUIRED)

add_executable(main main.cpp)

target_link_libraries(main opencv)

CMakeSettings.json is:

{
  // See https://go.microsoft.com//fwlink//?linkid=834763 for more information about this file.
  "configurations": [
    {
      "name": "x86-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "inheritEnvironments": [ "msvc_x86" ],
      "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
      "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": "",
      "variables": [
        {
          "name": "CMAKE_TOOLCHAIN_FILE",
          "value": "C:\\users\\ngu10t\\workspace\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake"
        }
      ]
    },
    {
      "name": "x86-Release",
      "generator": "Ninja",
      "configurationType": "RelWithDebInfo",
      "inheritEnvironments": [ "msvc_x86" ],
      "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
      "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": "",
      "variables": [
        {
          "name": "CMAKE_TOOLCHAIN_FILE",
          "value": "C:\\users\\ngu10t\\workspace\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake"
        }
      ]
    },
    {
      "name": "x64-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "inheritEnvironments": [ "msvc_x64" ],
      "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
      "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": "",
      "variables": [
        {
          "name": "CMAKE_TOOLCHAIN_FILE",
          "value": "C:\\users\\ngu10t\\workspace\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake"
        }
      ]
    },
    {
      "name": "x64-Release",
      "generator": "Ninja",
      "configurationType": "RelWithDebInfo",
      "inheritEnvironments": [ "msvc_x64" ],
      "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
      "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": "",
      "variables": [
        {
          "name": "CMAKE_TOOLCHAIN_FILE",
          "value": "C:\\users\\ngu10t\\workspace\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake"
        }
      ]
    }
  ]
}

Output when generating cache of CMakeLists.txt is:

1> Command line: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe  -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\ngu10t\CMakeBuilds\f73f3503-0fe4-d130-834f-aa25c0b54198\install\x86-Debug"  -DCMAKE_TOOLCHAIN_FILE="C:/users/ngu10t/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake"  -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\ngu10t\Workspace\Laava_tag"
1> Working directory: C:\Users\ngu10t\CMakeBuilds\f73f3503-0fe4-d130-834f-aa25c0b54198\build\x86-Debug
1> -- The C compiler identification is MSVC 19.11.25547.0
1> -- The CXX compiler identification is MSVC 19.11.25547.0
1> -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe
1> -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe -- works
1> -- Detecting C compiler ABI info
1> -- Detecting C compiler ABI info - done
1> -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe
1> -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe -- works
1> -- Detecting CXX compiler ABI info
1> -- Detecting CXX compiler ABI info - done
1> -- Detecting CXX compile features
1> -- Detecting CXX compile features - done
1> -- OpenCV ARCH: x86
1> -- OpenCV RUNTIME: vc15
1> -- OpenCV STATIC: ON
1> -- Found OpenCV: C:/Users/ngu10t/Workspace/vcpkg/installed/x86-windows (found version "3.3.1") 
1> -- Found OpenCV 3.3.1 in C:/Users/ngu10t/Workspace/vcpkg/installed/x86-windows/share/opencv/x86/vc15/lib
1> -- You might need to add C:\Users\ngu10t\Workspace\vcpkg\installed\x86-windows\share\opencv\x86\vc15\bin to your PATH to be able to run your applications.
1> -- Configuring done
1> -- Generating done
1> -- Build files have been written to: C:/Users/ngu10t/CMakeBuilds/f73f3503-0fe4-d130-834f-aa25c0b54198/build/x86-Debug
1> Starting CMake target info extraction ...
1> CMake server connection made.
1> Extracted includes paths.
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted global settings.
1> Extracted code model.
1> Collating data ...
1> Target info extraction done.

However, the above error shows up when I try to compile the solution via Build menu.

jasjuang commented 7 years ago

It should be

find_package(OpenCV REQUIRED)

add_executable(main main.cpp)

target_link_libraries(main ${OpenCV_LIBS})
JackBoosY commented 5 years ago

Hi @chuong , thanks for reporting this issue. I have tested the cmake configuration of opencv, they are correct in the latest version. Plz update vcpkg and rebuild it, then you may find notice as:

The package opencv provides CMake integration: \ find_package(OpenCV REQUIRED) target_include_directories(main PRIVATE ${OpenCV_INCLUDE_DIRS}) target_link_libraries(main PRIVATE ${OpenCV_LIBS})

Thx.