6

I'm trying to compile a simple code in visual studio + opencv, but got this error.

Code:

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main ( int argc, char **argv )

{
    Mat im_gray;
    Mat img_bw;
    Mat img_final;

    Mat im_rgb  = imread("001.jpg");
    cvtColor(im_rgb,im_gray,CV_RGB2GRAY);

    adaptiveThreshold(im_gray, img_bw, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV, 105, 1); 

    imwrite("001-bw2.jpg", img_final);
    return 0;
}  

Output:

1>------ Build started: Project: pibiti, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1104: cannot open file 'opencv_core231d.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The Linker >> Input:

opencv_core231d.lib
opencv_highgui231d.lib
opencv_video231d.lib
opencv_ml231d.lib
opencv_legacy231d.lib
opencv_imgproc231d.lib
tbb_debug.lib
tbb_preview_debug.lib
tbbmalloc_debug.lib
tbbmalloc_proxy_debug.lib
tbbproxy_debug.lib

How can I fix this? the file 'opencv_core231d.lib' is already there, why this error?

U23r
  • 1,653
  • 10
  • 28
  • 44
  • 2
    Does the `lib` actually exist on disk? Is the folder that it's in listed in the project properties under *Linker->General->Additional library directories*? – Roger Rowland Feb 13 '14 at 05:48
  • 1
    Please use CMake to generate your project files. It will make sure that all properties have been configured. – scap3y Feb 13 '14 at 06:04

5 Answers5

11

Add the path of the library files to the library path.

Right click the project and go to Properties->Linker->Additional Library directories. Add the path to this list.

littleimp
  • 1,159
  • 9
  • 13
  • 1
    Well this error only appears if the path is not added/wrong. If you add the correct path to your opencv lib files the error will go away. Make sure in Visual Studio you are always adding the paths to all your configurations (Debug/Release). Also check out this guide: http://stackoverflow.com/questions/7011238/opencv-2-3-c-visual-studio-2010 – littleimp Feb 18 '14 at 09:39
  • If any one is having this issue even if they have included the library files to the above Property field(s), Seeraj's answer might help you. Also might want to check the Configuration type in Properties, whether its Debug, Release etc. – Dilini Peiris Apr 21 '21 at 08:02
3

Adding to this list of solutions, mine was simply to change the project to 64 bit.

Tim Harding
  • 299
  • 1
  • 12
2

I had the same issue. Despite ensuring that the path to the libraries was correct, I was getting a "Cannot open file" error. The issue was I had named the dlls wrong in additional assembly references in Linker Properties. I had given them as above(with "231" at end). But the names of the actual Dlls were ending with "249". Changing that solved my issue. Might be helpful to others :-)

After this, project will get built successfully. But you can expect a run time error that opencv_core249d.lib is missing in your computer, you need to re-install it. That is becuase even though the path has been added to environment variables, windows has to be restarted to have it in effect. This will solve it.

Sreeraj
  • 2,306
  • 2
  • 18
  • 31
0

I had same problem so in Properties->Linker->Additional Library directories, I had to replace

$(OPENCV_DIR)\lib

with

C:\opencv\build\x86\vc12\lib

both in debug and release.

And now it works.

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
0

I had a similar issue - I solved it by changing the link in the path. Instead of: $(OPENCV_DIR)\lib or this kind of path C:\opencv\build\x86\vc12\lib just add \ at the end.

For me it worked with C:\opencv\build\x86\vc12\lib\ so I didn't try with the environment variable.

TripeHound
  • 2,721
  • 23
  • 37