You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Microsoft Visual Studio 2017链接OpenCV 3.4库?编译报错求助

Fixing "cannot open source file opencv2/highgui/highgui.hpp" in Visual Studio 2017 + OpenCV 3.4

Hey there, let's fix that include error step by step—this is a super common setup issue with OpenCV and Visual Studio, so you're not alone!

Step 1: Confirm your OpenCV installation path

First, nail down the exact folder where you installed/extracted OpenCV 3.4. The default path usually looks like:
C:\opencv\build
Inside this build folder, you’ll find two critical subfolders:

  • include: This is where all your opencv2/*.hpp header files live
  • x64/vc15/lib: Since you’re using VS2017 (which uses the VC15 toolset), this is the 64-bit library folder you need

Step 2: Configure Visual Studio's Include Directories

Open your VS2017 project, then:

  • Right-click your project in the Solution Explorer → Select Properties
  • In the left pane, navigate to Configuration Properties → VC++ Directories
  • Find the Include Directories field, click the dropdown arrow → Edit
  • Add the full path to your OpenCV include folder. For example:
    C:\opencv\build\include
  • Click OK to save the change

Step 3: Set Up the Library Directories

Still in the VC++ Directories section:

  • Locate Library Directories → Edit
  • Add the path to the 64-bit VC15 library folder for OpenCV 3.4:
    C:\opencv\build\x64\vc15\lib
  • Save this update

Next, tell the linker which .lib files to use:

  • In the project Properties pane, go to Configuration Properties → Linker → Input
  • Find Additional Dependencies → Edit
  • Add the matching library filename:
    • For Release mode: opencv_world340.lib
    • For Debug mode: opencv_world340d.lib
  • Click OK to apply

Step 5: Verify Platform Architecture Match

This is an easy mistake to slip up on!

  • Make sure your VS project is set to build for x64 (since you installed the x64 version of VC++ 2017)
  • Check the dropdown menu at the top of the VS window (next to Debug/Release) and select x64 instead of x86

Step 6: Double-Check Your Include Path

Your code uses #include<opencv2/highgui/highgui.hpp>—this is correct, but confirm the path exists:
Go to C:\opencv\build\include\opencv2 and make sure there’s a highgui subfolder with highgui.hpp inside it (it should be there by default for OpenCV 3.4).

Quick Runtime Fix (If Needed)

If the include error is gone but you get a missing DLL runtime error, copy opencv_world340.dll (or opencv_world340d.dll for Debug) from C:\opencv\build\x64\vc15\bin into your project’s output folder (where your .exe is built), or add that bin folder to your system’s PATH environment variable.


内容的提问来源于stack exchange,提问作者CL plane guy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:31:21