Search code examples
c++opencvvisual-studio-2019

I always get errors in linker with Visual Studio 2019 and OpenCV


I installed OpenCV-v2.4.11 from NuGet Package Manager in Microsoft Visual Studio 2019. However, I can't get working this code:

#include <opencv2/opencv.hpp>

int main()
{
    cv::Mat A;
    return 0;
}

I got these errors: Errors

Errors once more: (Visualisation is name of my project)

 - Severity Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree@cv@@YAXPEAX@Z) referenced in function "public: __cdecl cv::Mat::~Mat(void)" (??1Mat@cv@@QEAA@XZ)  Visualisation   C:\Users\maoap\source\repos\Visualisation\Visualisation\Source.obj  1   
 - Severity Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "public: void __cdecl cv::Mat::deallocate(void)" (?deallocate@Mat@cv@@QEAAXXZ) referenced in function "public: void __cdecl cv::Mat::release(void)" (?release@Mat@cv@@QEAAXXZ)   Visualisation   C:\Users\maoap\source\repos\Visualisation\Visualisation\Source.obj  1   
 - Severity Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@YAHPEAHH@Z) referenced in function "public: void __cdecl cv::Mat::release(void)" (?release@Mat@cv@@QEAAXXZ)   Visualisation   C:\Users\maoap\source\repos\Visualisation\Visualisation\Source.obj  1       
 - Severity Code    Description Project File    Line    Suppression State
Error   LNK1120 3 unresolved externals  Visualisation   C:\Users\maoap\source\repos\Visualisation\x64\Debug\Visualisation.exe   1   

Solution

  • As john wrote in a comment below the question:

    Visual Studio can show you the linker command line. Right click the project and pick properties. Then navigate to Configuration Properties/Linker/Command Line. Compare the command lines of the project that works and the one that doesn't, there must be a difference somewhere.