error LNK2001: 无法解析的外部符号 __imp__atof
在VC2008中,编写了一个静态库函数convertCStringToFloat,实现CString转double
convertCStringToFloat函数的头文件:
#include<atlstr.h>
#ifndef CONVERTCSTRINGTOFLOAT_H
#define CONVERTCSTRINGTOFLOAT_H
extern "C" void convertCStringToFloat(CString cstr, double & f); //声明为C编译、连接方式的外部函数
#endif
convertCStringToFloat函数的源文件:
#include "convertCStringToFloat.h"
void convertCStringToFloat(CString cstr, double & f)
{
int nLength=cstr.GetLength();
int nBytes =WideCharToMultiByte(CP_ACP,0,cstr,nLength,NULL,0,NULL,NULL);
char * pContentBuff=new char[nBytes+1];
memset(pContentBuff,0,nBytes+1);
WideCharToMultiByte(CP_ACP,0,cstr,nLength,pContentBuff,nBytes,NULL,NULL);
pContentBuff[nBytes]=0;
f=atof(pContentBuff);
}
在新建方案DRC中使用,添加了头文件和导入lin。如下:
#include "convertCStringToFloat.h"
#ifndef _LIB_
#ifdef _DEBUG
#pragma comment(lib,"convertCStringToFloatdebug.lib")
#else
#pragma comment(lib,"convertCStringToFloatrelease.lib")
#endif
#endif
在新建解决方案右击->属性->配置属性->链接器->输入中的“附加依赖项”中已添加lib库文件。
Debug时没有报错,Release时报错,如下:
error LNK2001: 无法解析的外部符号 __imp__atof e:\DRC\convertCStringToFloatrelease.lib