Error LNK1120: 1 unresolved externals

asked 2013-12-12 07:53:49 -0500

Nate Beghuk gravatar image

updated 2013-12-12 08:10:49 -0500

Hello expert..I'm getting an error when executing this code using my desktop. But when my friend execute this code by using his laptop, it works fine.Wonder whats wrong with it. I'm using Microsoft Visual Studio 2012. But my friend use Visual Studio 2010.

Here is the error

Error error LNK2019: unresolved external symbol _cvPyrSegmentation referenced in function "void __cdecl START_SEGMENT(int)" (?START_SEGMENT@@YAXH@Z)

Error error LNK1120: 1 unresolved externals

Can any of expert here help me, please? Thank you in advance for your help.

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/legacy/legacy.hpp>
#include <stdio.h>

static void help(void)
{
  printf("\nThis program present the function of pyramid segmentation which is       
         cvcvPyrSegmentation()\n""we can controlled the value of threshold by creating the   
         taskbar\n""Usage :\n");            
}

 IplImage*  image[2] = { 0, 0 }, *image0 = 0, *image1 = 0;
 CvSize size;

 int  w0, h0,i;
 int  threshold1, threshold2;
 int  l,level = 4;
 int sthreshold1, sthreshold2;
 int  l_comp;
 int block_size = 1000;
 float  parameter;
 double threshold;
 double rezult, min_rezult;
 int filter = CV_GAUSSIAN_5x5;
 CvConnectedComp *cur_comp, min_comp;
 CvSeq *comp;
 CvMemStorage *storage;

 CvPoint pt1, pt2;

 static void START_SEGMENT(int a)
{
  (void) a;
  cvPyrSegmentation(image0, image1, storage, &comp, level, threshold1+1, threshold2+1);

  cvShowImage("Segmentation", image1);
}


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

 help();

 filename = argc == 2 ? argv[1] : (char*)"C:/Users/acer/Documents/Visual Studio 
 2012/Projects/me2.jpg";

 if( (image[0] = cvLoadImage( filename, 1)) == 0 )
{
    help();
    printf("Cannot load fileimage - %s\n", filename);
    return -1;
}


cvNamedWindow("Source", 0);
cvShowImage("Source", image[0]);

cvNamedWindow("Segmentation", 0);

storage = cvCreateMemStorage ( block_size );

image[0]->width &= -(1<<level);
image[0]->height &= -(1<<level);

image0 = cvCloneImage( image[0] );
image1 = cvCloneImage( image[0] );
// segmentation of the color image
l = 1;
threshold1 =255;
threshold2 =30;

START_SEGMENT(1);

sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", &threshold1, 255, START_SEGMENT);
sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation",  &threshold2, 255, START_SEGMENT);

cvShowImage("Segmentation", image1);
cvWaitKey(0);

cvDestroyWindow("Segmentation");
cvDestroyWindow("Source");

cvReleaseMemStorage(&storage );

cvReleaseImage(&image[0]);
cvReleaseImage(&image0);
cvReleaseImage(&image1);

return 0;

}

#ifdef _EiC
main(1,"pyramid_segmentation.c");
#endif
edit retag flag offensive close merge delete

Comments

There is a lot of parameters here that can cause this problem, try to follow this tutorial (put a really big focus on the files names and the paths) https://www.youtube.com/watch?v=cgo0UitHfp8. Edit::Try first a really basic OpenCV example like what they did on the video to see if you configure OpenCV right.

itay gravatar imageitay ( 2013-12-12 08:01:34 -0500 )edit

Hello itay, yeah I'd already tried a really basic OpenCV few times before. It works fine. I tried all sorts of examples given in the tutorial provided by the OpenCV. It just fine.Working smoothly... Thanks for your comment.. :)

Just I said, I asked my friend to execute this code using his laptop, its work fine.No error at all.But he's using Visual Studio 2010 instead of me using Visual Studio 2012. He's getting no error but I am...wonder why...

Nate Beghuk gravatar imageNate Beghuk ( 2013-12-12 08:26:26 -0500 )edit

did you added all the include to the lib list? opencv_legacy246.lib opencv_imgproc246.lib opencv_highgui246.lib change OpenCV version depends on yours.

itay gravatar imageitay ( 2013-12-12 08:30:51 -0500 )edit

yes. added all the include to the lib list..

include <opencv2/imgproc/imgproc.hpp>

include <opencv2/highgui/highgui.hpp>

include <opencv2/imgproc/imgproc_c.h>

include <opencv2/imgproc/imgproc.hpp>

include <opencv2/legacy/legacy.hpp>

include <stdio.h>

I changed coding above to this :

include "opencv2/imgproc/imgproc.hpp"

include "opencv2/highgui/highgui.hpp"

include <stdlib.h>

include <stdio.h>

there is no Error LNK1120 anymore.But it turns out to have Error error C3861: 'cvPyrSegmentation': identifier not found ...HeadBanging..error error errorrrr.. Can somebody help me?? T_T

Nate Beghuk gravatar imageNate Beghuk ( 2013-12-12 09:26:24 -0500 )edit

Nate,

the short anwer: it's definitely in legacy.hpp ( guess what - you need opencv_legacy.lib as well ...)

the long anwer: please stop using the outdated c-api. it won't be supported for long, will hurt you and anyone around. please move over to C++ !!

berak gravatar imageberak ( 2013-12-12 09:46:38 -0500 )edit