生成.dll时,如果只有.dll,没有.lib,如何解决?(生成.DLL提供方用的是dllexport,使用方用的是dllimport,用个宏来代替)

来源:互联网 发布:js 对象未定义 编辑:程序博客网 时间:2024/06/05 10:37
原文:http://blog.csdn.net/kesalin/article/details/1612998
步骤:TrueSingDetect.dll对应函数所在的.h文件中加上方案一中的#if BUILDING_DLL  。。。。#endif /* Not BUILDING_DLL */中的内容,并在vs属性C/C++   预处理器  预处理器定义  中添加BUILDING_DLL,然后编译,就可在release中看见.dll和.lib(编译的是什么版本就看什么版本)
情况一:如果函数定义的类型是类
TrueSingDetect.h
#if BUILDING_DLL
# define DLLIMPORT _declspec (dllexport)
#else
# define DLLIMPORT _declspec (dllimport)
#endif

class DLLIMPORT TureSingJudge{

}
TrueSingDetect.cpp
TureSingJudge::TureSingJudge(){
}
TureSingJudge::~TureSingJudge(){
}


方案一:
TrueSingDetect.h
#ifndef _TrueSingDetect_H_
#define _TrueSingDetect_H_
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
DLLIMPORT int TrueSingDetect(void);
#endif

TrueSingDetect.cpp
#include "TrueSingDetect.h"
__declspec (dllexport) int TrueSingDetect(void){
int resulut=0;
return resulut;
}

方案二:
TrueSingDetect.h
#ifndef _TrueSingDetect_H_
#define _TrueSingDetect_H_
#define DllExport   __declspec( dllexport )
DllExport   int TrueSingDetect(void);
#endif

TrueSingDetect.cpp
#include "TrueSingDetect.h"
DllExport int TrueSingDetect(void){
int resulut=0;
return resulut;
}
0 0
原创粉丝点击