Search code examples
c++copencvlibrarieslnk2019

LNK2019: Unresolved External Symbol in OpenCV


I've been trying a few to days to configure the opencv library in Windows 10 and it's being quite a nightmare!

This is my code:

#include <opencv2/video.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <svm.h>
#include <stdio.h>

using namespace std;
using namespace cv;

int main(int argc, char** argv) {

    (...)

    /*2. PROCESAR VÍDEO*/

    int c;
    IplImage* color_img;
    CvCapture* cv_cap = cvCaptureFromCAM(0);
    cvNamedWindow("Video", 0); // create window
    for (;;) {
        color_img = cvQueryFrame(cv_cap); // get frame
        if (color_img != 0)
            cvShowImage("Video", color_img); // show frame
        c = cvWaitKey(10); // wait 10 ms or for key stroke
        if (c == 27)
            break; // if ESC, break and quit
    }
    /* clean up */

    cvReleaseCapture(&cv_cap);
    cvDestroyWindow("Video");
    return (EXIT_SUCCESS);
}

This is my Visual Studio 17 configuration:

  • In C/C++

C/C++

-In Linker:

linker image

In Linker/Input i've added the following libs:

  • opencv_calib3d345d.lib opencv_core345d.lib opencv_features2d345d.lib opencv_flann345d.lib opencv_highgui345d.lib opencv_imgproc345d.lib libpng.lib libtiff.lib zlib.lib IlmImf.lib libjasper.lib libjpeg-turbo.lib opencv_ml345d.lib opencv_objdetect345d.lib opencv_photo345d.lib opencv_stitching345d.lib opencv_superres345d.lib opencv_video345d.lib opencv_videostab345d.lib

Also: - I have opencv 3.4.5 version - running in x64 - I've built the library with cmake and VisualStudio17, after several tries with MINGW32, cygwin and Netbeans.

No error is showed in the IDE but when compiling shows the famous error "LNK2019 unresolved external symbol". I've tried with the recommendations of all the other posts with this topic but couldn't find the solution.

ERROR Image

Error LNK2019 símbolo externo "class cv::Mat __cdecl cv::imread(class cv::String const &,int)" (?imread@cv@@YA?AVMat@1@AEBVString@1@H@Z) sin resolver al que se hace referencia en la función main Project1 C:\Users\Mario I\source\repos\Project1\Project1\Main.obj 1

Error LNK2019 símbolo externo cvCreateCameraCapture sin resolver al que se hace referencia en la función main Project1 C:\Users\Mario I\source\repos\Project1\Project1\Main.obj 1

Error LNK2019 símbolo externo cvQueryFrame sin resolver al que se hace referencia en la función main Project1 C:\Users\Mario I\source\repos\Project1\Project1\Main.obj 1

Error LNK2019 símbolo externo cvReleaseCapture sin resolver al que se hace referencia en la función main Project1 C:\Users\Mario I\source\repos\Project1\Project1\Main.obj 1

Error LNK1120 4 externos sin resolver Project1 C:\Users\Mario I\source\repos\Project1\x64\Debug\Project1.exe 1


Solution

  • I am using the latest prebuild OpenCV 4.0 libraries with Windows 10, x64, and Visual Studio 2015. I setup it with using environment var:

    1. setx -m OPENCV_DIR D:\Vision\opencv\build\x64\vc14
    2. check it with - echo %OPENCV_DIR%
    3. for VS2015 Debug, Platform x64, enter the following Project settings:

    Additional Include Paths: $(OPENCV_DIR)....\include

    Additional Library Directories: %OPENCV_DIR%\lib

    Additional Dependencies: opencv_world400d.lib;

    1. for VS Release

    Additional Dependencies: opencv_world400.lib;

    Be careful Platform to be set to x64.

    Also see: https://docs.opencv.org/3.0-rc1/d3/d52/tutorial_windows_install.html#tutorial_windows_install_path