接口导出的h文件与cpp文件分离

来源:互联网 发布:软件开发面试题 编辑:程序博客网 时间:2024/06/05 08:34

在接口导出的头文件中,会有一些enum和struct,这些都是随api导出的,但是在cpp和内部的实现文件中,最好不应该include 这个api的头文件的,因此怎么实现其分离呢?


例子如下:

123.h

#ifndef _123_H_
#define _123_H_

#ifdef __cplusplus
extern "C" {
#endif

int Add(int a, int b);

#ifdef __cplusplus
}
#endif

#endif


123.cpp

#define PIC_EXPORT2  extern "C" __declspec(dllexport)

PIC_EXPORT2 int Add(int a, int b){
    return a + b;
}


我们在cpp中导出,这样可以了。


0 0
原创粉丝点击