VC常见链接错误

1、   LNK2019    无法解析的外部符号 "void __cdecl tt_Audi_SearchCommand(int,unsigned char *)" (?tt_Audi_SearchCommand@@YAXHPAE@Z),该符号在函数 "unsigned int __cdecl tt_CANBUSMileageServiceReset(int,unsigned char *,int)" (?tt_CANBUSMileageServiceReset@@YAIHPAEH@Z) 中被引用    X431_vw_oilreset    C:\Users\64129\documents\visual studio 2015\Projects\X431\X431_vw_oilreset\funcOilReset.obj    1    生成    
原因: 函数tt_Audi_SearchCommand有声明,没定义

2、1>libStd.obj : error LNK2019: 无法解析的外部符号 "void __cdecl DSCalculate(unsigned char,unsigned char,unsigned char,char *)" (?DSCalculate@@YAXEEEPAD@Z),该符号在函数 "unsigned int __cdecl tt_SpecFuncShowBas(struct sysInfo *,unsigned char *,int)" (?tt_SpecFuncShowBas@@YAIPAUsysInfo@@PAEH@Z) 中被引用
原因: 就是声明和定义格式不一样

3、1>funcOilReset.obj : error LNK2005: "unsigned int sysInfoId" (?sysInfoId@@3IA) 已经在funcEPB.obj中定义
1>libStd.obj : error LNK2005: "unsigned int sysInfoId" (?sysInfoId@@3IA) 已经在 funcEPB.obj 中定义
1>ThrottleBodyAdaption.obj : error LNK2005: "unsigned int sysInfoId" (?sysInfoId@@3IA) 已经在 funcEPB.obj 中定义
原因:多重定义,往往是由于全局变量引起的;
我将extern unsigned int sysInfoId;//系统ID 定义在 libStd.h中,然后 funOilReset 、 ThrottleXX.cpp、libstd.cpp 都去include "libStd.h"
这样,就在三个cpp编译成的obj中都有,导致重复定义;
解决方法1: 将全局变量定义在一个cpp中,在其他的文件中使用extern unsigned int sysInfoId;

4、D_decode.obj : error LNK2005: "char * ReadPath" (?ReadPath@@3PADA) 已经在 Head_decode.obj 中定义。
原因:同3,全局变量的重复使用

解决方法2:当.cpp 太多的时候,
在随便一个.cpp 中“定义”全局变量(int B=0;),在一个头文件A.h中添加声明 extern B;  ,然后在所有其他需要使用全局变量B的.cpp 文件中include “A.h”

 

 

 


 


版权声明:本文为yuqian123455原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。