error LINK2001无法解析的外部符号解决办法

error LINK2001无法解析的外部符号解决办法

       在对VS调试程序时会经常出现”error LINK2001无法解析的外部符号”的链接错误,导致出现这类错误的原因是有很多,下面就介绍一下大多数人最容易犯的两个低级错误导致链接出错的示例。

1.1 错误如下:
minimal.obj : error LNK2001: 无法解析的外部符号 "void __cdecl fatigueJudage(class cv::Mat,bool,class cv::Mat_,int,double,class cv::Rect_,class cv::Rect_,class cv::Rect_,class cv::Rect_)" (?fatigueJudage@@YAXVMat@cv@@_NV?$Mat_@N@2@HNV?$Rect_@H@2@333@Z)
1>E:\KCF+stasm77+bc\vc10\\minimal.exe : fatal error LNK1120: 1 个无法解析的外部命令

1.2 出错原因:声明与定义不一致导致出错(下例中SrcImg前的引用符号)
声明:void fatigueJudage(cv::Mat SrcImg, bool DayOrNight, cv::Mat_ Current_Shape,
int frame_count, double t_fps, cv::Rect faceRect,
cv::Rect LeftEyeRect, cv::Rect RightEyeRect, cv::Rect MouthRect);

定义:void fatigueJudage(cv::Mat &SrcImg, bool DayOrNight, cv::Mat_ Current_Shape,
int frame_count, double t_fps, cv::Rect faceRect,
cv::Rect LeftEyeRect, cv::Rect RightEyeRect, cv::Rect MouthRect)

2.1 错误如下:
mian.obj : error LNK2001: 无法解析的外部符号 "struct polar __cdecl rect_to_polar(struct rect)" (?rect_to_polar@@YA?AUpolar@@Urect@@@Z)
1>mian.obj : error LNK2001: 无法解析的外部符号 "void __cdecl show_polar(struct polar)" (?show_polar@@YAXUpolar@@@Z)
1>C:\Users\DELL\Desktop\test\Release\test.exe : fatal error LNK1120: 2 个无法解析的外部命令

相应代码:
#include "coordin.h"
#include
int main()
{
	using namespace std;
	rect rplace;
	polar pplace;
	cout << "enter two number x and y:";
	while (cin>>rplace.x>>rplace.y)
	{
		pplace = rect_to_polar(rplace);
		show_polar(pplace);
		cout << "next two number (q to exit):";
	}
	cout << "bye!\n";
	return 0;
}

2.2 出错原因:源文件中未包含程序所需的coordin.cpp文件导致出现链接错误

       链接出错原因纷繁复杂,要根据具体情况具体分析。以上仅仅是导致链接出错最常见的两类原因。后续在调试程序中出现其他的链接出错时,再来丰富一下。

你可能感兴趣的:(代码调试异常解决方案)