可能重复:
What is an undefined reference/unresolved external symbol error and how do I fix it?
我正在使用Visual Studio 2010和OpenCV库。 当我尝试编译以下代码时,我收到以下错误:
错误LNK2001:未解析的外部符号“class cv :: Mat __cdecl grdX(class cv :: Mat)”(?grdX @@ YA?AVMat @ cv @@ V12 @@ Z)
错误LNK1120:1个未解析的外部
//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;
}
我找不到代码中的错误。
答案 0 :(得分:2)
您需要在项目属性中指定库所在的位置。在链接器中 - &gt;一般/输入。 在您的情况下,CV库