Ask Your Question
0

Getting LINK2001 error in MSVS2017 although I have added both lib files to dependencies

asked 2018-11-26 21:59:38 -0600

Chubak gravatar image

updated 2018-11-26 22:54:44 -0600

I'm getting this error in MSVS2017:

 1>------ Build started: Project: OpenCLTest, Configuration: Release x64 ------
1>OpenCLTest.obj : error LNK2001: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@YAHPEAHH@Z)
1>c:\users\chubak\documents\visual studio 2017\Projects\OpenCLTest\x64\Release\OpenCLTest.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "OpenCLTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

For this code:

#include "stdafx.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv;

int main()
{
    Mat image = imread("C:\\Users\\Chubak\\Pictures\\index.jpg");
    if (image.empty())
        return -1;
    imshow("TEST", image);
    waitKey();

    return 0;
}

Although I have added:

C:\opencv\build\x64\vc15\lib\opencv_world400.lib
C:\opencv\build\x64\vc15\lib\opencv_world400d.lib

To the dependencies. Why?

Edit: I just found out there are prebuilt libraries in NuGet, so I downloaded them:

C:\Users\Chubak\Documents\Visual Studio 2017\Projects\OpenCLTest\packages\OpenCV.Win.Core.310.6.1\build\native\win10-x64\opencv_core310.lib
C:\Users\Chubak\Documents\Visual Studio 2017\Projects\OpenCLTest\packages\OpenCV.Win.ImgCodecs.310.6.1\build\native\win10-x64\opencv_imgcodecs310.lib
C:\Users\Chubak\Documents\Visual Studio 2017\Projects\OpenCLTest\packages\OpenCV.Win.ImgProc.310.6.1\build\native\win10-x64\opencv_imgproc310.lib
C:\Users\Chubak\Documents\Visual Studio 2017\Projects\OpenCLTest\packages\OpenCV.Win.HighGUI.310.6.1\build\native\win10-x64\opencv_highgui310.lib
C:\Users\Chubak\Documents\Visual Studio 2017\Projects\OpenCLTest\packages\OpenCV.Win.Calib3D.310.6.1\build\native\win10-x64\opencv_calib3d310.lib
C:\Users\Chubak\Documents\Visual Studio 2017\Projects\OpenCLTest\packages\OpenCV.Win.Features2D.310.6.1\build\native\win10-x64\opencv_features2d310.lib
C:\Users\Chubak\Documents\Visual Studio 2017\Projects\OpenCLTest\packages\OpenCV.Win.FLANN.310.6.1\build\native\win10-x64\opencv_flann310.lib
C:\Users\Chubak\Documents\Visual Studio 2017\Projects\OpenCLTest\packages\OpenCV.Win.ML.310.6.1\build\native\win10-x64\opencv_ml310.lib
C:\Users\Chubak\Documents\Visual Studio 2017\Projects\OpenCLTest\packages\OpenCV.Win.Video.310.6.1\build\native\win10-x64\opencv_video310.lib
C:\Users\Chubak\Documents\Visual Studio 2017\Projects\OpenCLTest\packages\OpenCV.Win.VideoIO.310.6.1\build\native\win10-x64\opencv_videoio310.lib

But I still get three, exactly three unresolved externals errors:

1>------ Build started: Project: OpenCLTest, Configuration: Release x64 ------
1>OpenCLTest.obj : error LNK2001: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@YAHPEAHH@Z)
1>OpenCLTest.obj : error LNK2001: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?imread@cv@@YA?AVMat@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z)
1>OpenCLTest.obj : error LNK2001: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow@cv@@YAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV_InputArray@1@@Z)
1>c:\users\chubak\documents\visual studio 2017\Projects\OpenCLTest\x64\Release\OpenCLTest.exe ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-11-26 23:06:59 -0600

berak gravatar image

updated 2018-11-26 23:10:30 -0600

adding both debug and release libs is wrong. add the release one to your release project, and the debug one to your debug project ONLY !

also note, tht opencv does not maintain any nuget packages, and that mixing outdated 3.1.0 libs from there with you current opencv_world400 won't work at all.

edit flag offensive delete link more

Comments

I'm not mixing them. i removed the debug version, and my project is set to release. I still get LNK2001 error with opencv_world400.lib. It's like, my code is deprecated. Could you check please?

Chubak gravatar imageChubak ( 2018-11-26 23:28:00 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-11-26 21:59:38 -0600

Seen: 1,142 times

Last updated: Nov 26 '18