如何让Microsoft 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 youropencv2/*.hppheader files livex64/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
includefolder. 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
Step 4: Link the OpenCV Libraries
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
- For Release mode:
- 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

