关于inconsistent dll linkage. dllexport assumed.的警告如何解决?
我用WIN32 Dynamic-Link Library的方式建立了一个空项目。希望做一个DLL类导出。代码如下:IODll.h
#ifndef IODll_H
#define IODll_H
//#include "stdafx.h "
#include <windows.h>
#include "driver.h "
#include "os.h "
#ifdef DLL_FILE
class _declspec(dllexport) CPort //导出类circle
#else
class _declspec(dllimport) CPort //导入类circle
#endif
{
public:
int Power(int nBase, int nPow);
int StringToDec(char *szStr, int nBase);
};
#endif
IODll.cpp
#include "IODll.h "
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
int CPort::StringToDec(char *szStr, int nBase)
{
int i,j,nValue, nResult;
char cNum;
nResult = 0;
for(i = strlen(szStr)-1, j = 0; i > =0 ; --i,++j)
{
cNum = *(szStr+i);
if(cNum > = '0 ' && cNum <= '9 ')
nValue = (int)(cNum - '0 ');
else
{
cNum = tolower(cNum);
nValue = (int)(cNum - 'a ') + 10;
}
nResult = nResult + Power(nBase, j)* nValue;
}
return (nResult);
}
int CPort::Power(int nBase, int nPow)
{
int nValue,i;
if(nPow == 0)
return(1);
nValue = 1;
for(i = nPow; i > 0; i--)
nValue = nValue * nBase;
return(nValue);
}
编译出现了两个警告:
E:\ETC\IODll\IODll.cpp(26) : warning C4273: 'StringToDec ' : inconsistent dll linkage. dllexport assumed.
E:\ETC\IODll\IODll.cpp(47) : warning C4273: 'Power ' : inconsistent dll linkage. dllexport assumed.
请问如何解决?
[解决办法]
函数定义前面也加上_declspec
[解决办法]
在IODll.cpp中的
#include "IODll.h " 之前加入:
#define DLL_FILE