Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?爲什麼我得到一個錯誤LNK2001和LNK1120
我與Visual Studio 2010和庫OpenCV的工作。 當我嘗試編譯下面的代碼我得到這些錯誤:
錯誤LNK2001:?解析的外部符號 「類品種::墊__cdecl grdX(CV類:: MAT)」(grdX @@ YA AVMat @簡歷@@ 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;
}
我找不到什麼是錯在我的代碼。
我的壞,這是 - > http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how -do-i-fix/12574403#12574403 –
你正在聲明'Mat grdX(Mat);'並執行'Mat grdX(Mat_ matrix)'。 –
你也可能希望'grdX'通過引用而不是像現在這樣使用它的參數,它顯然會複製你的整個JPEG只是爲了將它傳遞給函數。 –