c++ 运行调试出现这个错误 fatal error LNK1120: 9 unresolved externals
代码段:
#include "stdafx.h"
#include "S180006CAPIExampleComEn.h"
#include "S180006CAPIExampleComEnDlg.h"
#include "SeRFIDepcApi.h" //引用EPC API头文件
#include "SeRFIDPub.h" //引用公共API头文件
#include<iostream>
using namespace std;
void main()
{
HANDLE g_hCom; //串口句柄变量
unsigned char g_RAddr = 0xFF; //读写器的地址变更
status = SeRFIDpub_Open(g_hCom,"COM1");
if (status != ERR_NONE)
{
printf("打开串口失败! ");
}
else //否则,打开串口成功
{
printf("打开串口成功! ");
unsigned char BaudRateIndex = 0x08; //波特率115200bps的序号值是0x08,详情请参考//SeRFIDpub_SysSetBaudRate API说明。
status = SeRFIDpub_SysSetBaudRate(g_hCom,g_RAddr,BaudRateIndex);//设置波特率
if(status == ERR_NONE)
{
printf("设置波特率为115200bps成功! ");
}
}
unsigned char TagCount = 0x00;// 返回的标签数变量
unsigned char TagData[64]; //返回的标签号数组
unsigned char QValue = 2;
unsigned char Bank = 1, Point = 0,ReadLen = 12; //标签号的块地址,与块内偏移量,以及标签长度.
unsigned char MaskLength = 0; //用于匹配的长为0,即不匹配标签,对所有标签都进行操作。
unsigned char Mask[16]; //匹配数据变量数组。
int i;
//启动多标签读。
status =SeRFIDGen2_MultiRead(g_hCom,g_RAddr,QValue,Bank,Point,ReadLen,MaskLength,Mask);
//参数说明: g_hCom:传入串口句柄,g_RAddr:读写器地址
if (status == ERR_NONE)
{
SeRFIDGen2_End(g_hCom, g_RAddr); //结束多标签读
SeRFIDpub_BufGetTagNum(g_hCom, g_RAddr, &TagCount); //取已经读出的标签数
for(i=0;i<TagCount;i++)
{
//从读写器缓冲区中取一个标签数据,同时读写器删除该组标签数据(TagData[])。
status = SeRFIDpub_BufGetOneAndClear(g_hCom, g_RAddr, TagData);
//参数说明: TagData:返回的标签号数组
if (status == ERR_NONE)
{
printf("标签号为:");
for(int i=1;i<TagData[0];i++) //TagData[0],是数据长度,取标签号要从TagData[1]开始
printf("%02X ",TagData[i]); //输出标签号
}
}
}
}
错误信息
Linking...
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in libcpd.lib(delop.obj)
Connection_read.obj : error LNK2001: unresolved external symbol "short __stdcall SeRFIDpub_BufGetOneAndClear(void *,unsigned char,unsigned char *)" (?SeRFIDpub_BufGetOneAndClear@@YGFPAXEPAE@Z)
Connection_read.obj : error LNK2001: unresolved external symbol "short __stdcall SeRFIDpub_BufGetTagNum(void *,unsigned char,unsigned char *)" (?SeRFIDpub_BufGetTagNum@@YGFPAXEPAE@Z)
Connection_read.obj : error LNK2001: unresolved external symbol "short __stdcall SeRFIDGen2_End(void *,unsigned char)" (?SeRFIDGen2_End@@YGFPAXE@Z)
Connection_read.obj : error LNK2001: unresolved external symbol "short __stdcall SeRFIDGen2_MultiRead(void *,unsigned char,unsigned char,unsigned char,unsigned char,unsigned char,unsigned char,unsigned char * const)" (?SeRFIDGen2_MultiRead@@YGFPAXEE
EEEEQAE@Z)
Connection_read.obj : error LNK2001: unresolved external symbol "short __stdcall SeRFIDpub_SysSetBaudRate(void *,unsigned char,unsigned char)" (?SeRFIDpub_SysSetBaudRate@@YGFPAXEE@Z)
Connection_read.obj : error LNK2001: unresolved external symbol "short status" (?status@@3FA)
Connection_read.obj : error LNK2001: unresolved external symbol "short __stdcall SeRFIDpub_Open(void * &,char *)" (?SeRFIDpub_Open@@YGFAAPAXPAD@Z)
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/Connection_read.exe : fatal error LNK1120: 9 unresolved externals
执行 link.exe 时出错.
[解决办法]
缺少lib,你到msdn中找找报错的函数需要什么xxx.lib文件。在编译选项中把xxx.lib加上去