动态库在windows和linux上编译适配

43 阅读1分钟

windows上导出动态库需要使用__declspec(dllexport),而linux上不需要,并且会报错,需要通过宏_WIN32,使对windows生效的定义在linux上不生效

#ifndef _HG_REDIS_DB_API_H_
#define _HG_REDIS_DB_API_H_

#ifdef _WIN32
#ifdef HG_REDIS_DB_API_EXPORT
#define HG_REDIS_DB_API __declspec(dllexport)
#else 
#define HG_REDIS_DB_API __declspec(dllimport)
#endif //HG_REDIS_DB_API_EXPORT
#else
#define HG_REDIS_DB_API
#endif // _WIN32

#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

	//初始化数据库链接
	HG_REDIS_DB_API void HG_Redis_Login(char* IP, int port, char*password);

	//读
	HG_REDIS_DB_API void HG_Redis_ReadDBData(const char *in_vecKey[], double *out_vecValue, int in_size);

	//写
	HG_REDIS_DB_API void HG_Redis_Write2DB(const char *in_vecKey[], double *in_vecValue, int in_size);

	//退出登录
	HG_REDIS_DB_API void HG_Redis_Logout();

#ifdef __cplusplus
}
#endif // __cplusplus


#endif // _HG_REDIS_DB_API_H_