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”

 

 

 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值