-2

Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?

I'm working with Visual Studio 2010 and the library OpenCV. When I try to compile the following code I get these error:

error LNK2001: unresolved external symbol "class cv::Mat __cdecl grdX(class cv::Mat)" (?grdX@@YA?AVMat@cv@@V12@@Z)

error LNK1120: 1 unresolved externals

//Includes
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>

using namespace std;
using namespace cv;

//Prototypes
Mat grdX(Mat);
Mat grdY(Mat);

int main()
{
    Mat_<uchar> mat = imread("C:/img.jpg");
    int row = mat.rows;
    int col = mat.cols;
    Mat_<uchar> f(row, col);
    f = grdX(mat);
    namedWindow ("img2", CV_WINDOW_AUTOSIZE);
    imshow ("img2", f);
    return EXIT_SUCCESS;
}


Mat grdX(Mat_<uchar> matrix)
{
    int row = matrix.rows;
    int col = matrix.cols;
    Mat_<uchar> grd(row,col);
    for (int i=1; i<=row ;i++)
        {
            for (int j=1; j<=col; j++)
            {
                if (j==1)
                {grd(i,1) = (int)matrix(i,2)-(int)matrix(i,1);}
                else if (j==col)
                {grd(i,col) = (int)matrix(i,col)-(int)matrix(i,col-1);}
                else {grd(i,j)=((int)matrix(i,j+1)-(int)matrix(i,j-1))/2;}
            }
        }
    return grd;
}

Mat grdY(Mat_<uchar> matrix)
{
    int row = matrix.rows;
    int col = matrix.cols;
    Mat_<uchar> grd(row,col);
    for (int i=1; i<=row ;i++)
        {
            for (int j=1; j<=col; j++)
            {
                if (i==1)
                {grd(1,j) = (int)matrix(2,j)-(int)matrix(1,j);}
                else if (i==row)
                {grd(row,j) = (int)matrix(row,j)-(int)matrix(row-1,j);}
                else {grd(i,j)=((int)matrix(i+1,j)-(int)matrix(i-1,j))/2;}
            }
        }
    return grd;
}

I can't find what is wrong in my code.

Community
  • 1
  • 1
alvinleetya
  • 454
  • 2
  • 7
  • 19
  • My bad, it's this -> http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix/12574403#12574403 – Luchian Grigore Oct 02 '12 at 14:21
  • You're declaring `Mat grdX(Mat);` and implementing `Mat grdX(Mat_ matrix)`. – Luchian Grigore Oct 02 '12 at 14:22
  • You also probably want to have `grdX` take its parameter by reference rather than value -- as-is, it'll apparently copy your entire JPEG just to pass it to the function. – Jerry Coffin Oct 02 '12 at 14:31

1 Answers1

2

You need to specify in the project properties where your library is. In Linker --> General/Input. In your case the CV library

ISTB
  • 1,799
  • 3
  • 22
  • 31