zl程序教程

您现在的位置是:首页 >  工具

当前栏目

#ifdef _cplusplus extern “C“ 含义及应用

应用 含义 extern
2023-09-14 09:05:45 时间

#ifdef _cplusplus:编译器如果是C++   

extern"C" 来告诉编译器:这是一个用C写成的库文件,请用C的方式来链接它们。

他们经常出现在.h文件中。

例:

#ifndef _INC_MYSOCKETCLIENT_H_
#define _INC_MYSOCKETCLIENT_H_
//#define Import_SSS
#ifdef Import_SSS
#define API _declspec(dllexport)
#else 
#define API _declspec(dllimport)
#endif

#ifdef _cplusplus//extern"C" 来告诉编译器:这是一个用C写成的库文件,请用C的方式来链接它们。
extern "C" {
#endif // _cplusplus
	API//导出函数,让外界调用。
	int socketClient_Init(void **handle);
	API
	int socketClient_Send(void *handle, unsigned char *buf, int buflen);
	API
	int socketClient_Recv(void *handle, unsigned char *buf, int *buflen);
	API
	int socketClient_Destory(void *handle);
#ifdef _cplusplus
}
#endif // _cplusplus
#endif //_INC_MYSOCKETCLIENT_H_