C++ OpenCV 错误:“链接:致命错误 LNK1104:无法打开文件‘opencv_core231d.lib’”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21744464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:48:10  来源:igfitidea点击:

OpenCV error: "LINK : fatal error LNK1104: cannot open file 'opencv_core231d.lib' "

c++opencvimage-processingerror-handling

提问by U23r

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

我正在尝试在 Visual Studio + opencv 中编译一个简单的代码,但出现此错误。

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?

我怎样才能解决这个问题?文件“opencv_core231d.lib”已经存在,为什么会出现这个错误?

回答by littleimp

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.

右键单击该项目并转到 Properties->Linker->Additional Library 目录。将路径添加到此列表中。

回答by Tim Harding

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

添加到此解决方案列表中,我的只是将项目更改为 64 位。

回答by Sreeraj

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 :-)

我遇到过同样的问题。尽管确保库的路径正确,我还是收到了“无法打开文件”的错误。问题是我在链接器属性中的附加程序集引用中将 dll 命名为错误。我已经给了他们如上(最后是“231”)。但实际 Dll 的名称以“249”结尾。改变它解决了我的问题。可能对其他人有帮助:-)

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.

在此之后,项目将成功构建。但是您可能会遇到计算机中缺少 opencv_core249d.lib 的运行时错误,您需要重新安装它。这是因为即使路径已添加到环境变量中,也必须重新启动 Windows 才能使其生效。这将解决它。

回答by Abhijeet Sinha

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

我遇到了同样的问题,所以在Properties->Linker->Additional Library directory 中,我不得不替换

$(OPENCV_DIR)\lib

with

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

both in debug and release.

在调试和发布中。

And now it works.

现在它起作用了。

回答by life_saver

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

我有一个类似的问题 - 我通过更改路径中的链接解决了它。而不是:$(OPENCV_DIR)\lib或者这种路径C:\opencv\build\x86\vc12\lib只是\在最后添加。

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

对我来说,它可以工作,C:\opencv\build\x86\vc12\lib\所以我没有尝试使用环境变量。