// Macros.h
#pragma once #if defined(__GNUC__)
#define _DEPRECATED_ __attribute__((deprecated))
#define _FORCE_INLINE_ __attribute__((always_inline))
#elif defined(_MSC_VER)
#define _DEPRECATED_
#define _FORCE_INLINE_ __forceinline
#else
#define _DEPRECATED_
#define _FORCE_INLINE_ inline
#endif /*
Windows import/export and gnu http://gcc.gnu.org/wiki/Visibility
macros.
*/
#if defined(_MSC_VER)
#define DLL_IMPORT __declspec(dllimport)
#define DLL_EXPORT __declspec(dllexport)
#define DLL_LOCAL
#elif __GNUC__ >= 4
#define DLL_IMPORT __attribute__ ((visibility("default")))
#define DLL_EXPORT __attribute__ ((visibility("default")))
#define DLL_LOCAL __attribute__ ((visibility("hidden")))
#else
#define DLL_IMPORT
#define DLL_EXPORT
#define DLL_LOCALs
#endif // Ignore warnings about import/exports when deriving from std classes.
#ifdef _MSC_VER
#pragma warning(disable: 4251)
#pragma warning(disable: 4275)
#endif // Import/export for windows dll's and visibility for gcc shared libraries. #ifdef BUILD_SHARED_LIBS // project is being built around shared libraries
#ifdef CLASS_EXPORTS // we are building a shared lib/dll
#define CLASS_DECL DLL_EXPORT
#else // we are using shared lib/dll
#define CLASS_DECL DLL_IMPORT
#endif #ifdef FUNC_EXPORTS // we are building a shared lib/dll
#define FUNC_DECL DLL_EXPORT
#else // we are using shared lib/dll
#define FUNC_DECL DLL_IMPORT
#endif
#else // project is being built around static libraries
#define CLASS_DECL
#define FUNC_DECL
#endif

Example:

#if defined _WIN32 || defined __CYGWIN__
#ifdef BUILDING_DLL
#ifdef __GNUC__
#define DLL_PUBLIC __attribute__ ((dllexport))
#else
#define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
#endif
#else
#ifdef __GNUC__
#define DLL_PUBLIC __attribute__ ((dllimport))
#else
#define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
#endif
#endif
#define DLL_LOCAL
#else
#if __GNUC__ >= 4
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
#define DLL_LOCAL __attribute__ ((visibility ("hidden")))
#else
#define DLL_PUBLIC
#define DLL_LOCAL
#endif
#endif extern "C" DLL_PUBLIC void function(int a);
class DLL_PUBLIC SomeClass
{
int c;
DLL_LOCAL void privateMethod(); // Only for use within this DSO(Dynamic Shared Object)
public:
Person(int _c) : c(_c) { }
static void foo(int a);
};

参考:

  http://gcc.gnu.org/wiki/Visibility

C++跨平台类库导出宏的更多相关文章

  1. C++开源跨平台类库集

    在如下的库支持下,开发的系统可以很方便移植到当前大部分平台上运行而无需改动,只需在对应的平台下 用你喜欢的编译器 重新编译即可 经典的C++库   STLport-------SGI STL库的跨平台 ...

  2. 拥抱.NET Core,如何开发一个跨平台类库 (1)

    在此前的文章中详细介绍了使用.NET Core的基本知识,如果还没有看,可以先去了解“拥抱.NET Core,学习.NET Core的基础知识补遗”,以便接下来的阅读. 在本文将介绍如何配置类库项目支 ...

  3. Xamarin+Prism开发详解一:PCL跨平台类库与Profile的关系

    在[Xamarin+Prism小试牛刀:定制跨平台Outlook邮箱应用]中提到过以下错误,不知道大伙还记得不: 无法安装程序包"Microsoft.Identity.Client 1.0. ...

  4. dll导入导出宏定义,出现“不允许 dllimport 函数 的定义”的问题分析

    建立dll项目后,在头文件中,定义API宏 #ifndef API_S_H #define API_S_H ...... #ifndef DLL_S_20160424 #define API _dec ...

  5. 使用phpexecel类库导出数据

    公司要求做一个功能:将数据库里的数据导出,并生成excel文件. 于是百度了下,集大牛之所长,加上自己之所长,做出了整理,并分享. 目标:使用phpexcel类库生成xml文件,并下载. 步骤一:下载 ...

  6. 用excel.php类库导出excel文件

    excel.php是个小型的php类库,可以满足基本的从数据库中取出数据然后导出xls格式的excel文件,代码如下: 1 class Excel { 2 public $filename = 'ex ...

  7. .Net Core跨平台应用研究-CustomSerialPort(增强型跨平台串口类库)

    .Net Core跨平台应用研究-CustomSerialPort -增强型跨平台串口类库 摘要 在使用SerialPort进行串口协议解析过程中,经常遇到接收单帧协议数据串口接收事件多次触发,协议解 ...

  8. .NET Core 系列5 :使用 Nuget打包类库

    NuGet是个开源项目,项目包括 NuGet VS插件/NuGet Explorer/NuGetServer/NuGet命令行等项目,.NET Core项目完全使用Nuget 管理组件之间的依赖关系, ...

  9. 导出数据到Excel --使用ExcelReport有感

    先看图,这是几个月前用NPOI写的导出数据到Excel,用了上百行代码,而且难控制,导出来也比较难看 excel打开的效果 下面是我用ExcelReport类库导出到Excel的操作 1.首先引用Ex ...

  10. NPOI、MyXls、Aspose.Cells 导入导出Excel(转)

    Excel导入及导出问题产生: 从接触.net到现在一直在维护一个DataTable导s出到Excel的类,时不时还会维护一个导入类.以下是时不时就会出现的问题: 导出问题: 如果是asp.net,你 ...

随机推荐

  1. Go语言使用场景 | go语言与其它开源语言比较 | Go WEB框架选型

    一.Go语言使用场景 1. 关于go语言 2007年,受够了C++煎熬的Google首席软件工程师Rob Pike纠集Robert Griesemer和Ken Thompson两位牛人,决定创造一种新 ...

  2. table表格的合并

    如上图,实现单元格合并功能,不多说,直接上代码 一,添加    :span-method="objectSpanMethod" <el-table :key="ti ...

  3. Spring中使用@RequestBody注解接收的实体类中的某些参数为null

    1.问题描述 我写完一个接口,在用postman测试的时候,发现其中有一个参数cEnterpriseId明明是有值的,但接口controller接收到的该参数为null,但其他参数都不为null的. ...

  4. Android录屏实现

    使用方案: mediacodec + mediaprojection + mediamuxer MediaProjectionManager主要作用是获得录屏权限 startActivityForRe ...

  5. ES6 中 Promise对象使用学习

    转载请注明出处: Promise 对象是 JavaScript 的异步操作解决方案,为异步操作提供统一接口.它起到代理作用(proxy),充当异步操作与回调函数之间的中介,使得异步操作具备同步操作的接 ...

  6. 在GCP上创建Cloud SQL的三种方式(Console,gcloud,Terraform)

    1 简介 Cloud SQL 是GCP上的关系型数据库,常用的有三种方式来创建: (1) 界面操作 (2) 命令行 gcloud (3) Terraform 在开始之前,可以查看:<初始化一个G ...

  7. MySQL 嵌套子查询 with子句 from子查询 in子查询 join组合

    一.适用场景和方法 (1)适用场景 考虑查询过程中是否存在以下情况: 查询某些数据时需要分组才能得到,某些数据不需要分组就能得到或者分组条件不同: 查询某些数据时需要where条件,某些列不需要whe ...

  8. VUE基础之:visible.sync-模态框显示隐藏、elementUI dialog组件报错或者visible属性不生效问题

    VUE基础之:visible.sync-模态框显示隐藏.elementUI dialog组件报错或者visible属性不生效问题 这篇文档存成草稿2年了,最近终于有时间拉出来写完了.... 我们日常开 ...

  9. 使用docker安装hadoop(已实现)

    1.拉镜像 这里推荐第一个 docker pull registry.cn-hangzhou.aliyuncs.com/hadoop_test/hadoop_base 或者 docker pull q ...

  10. Python自动批量修改文件名称的方法

      本文介绍基于Python语言,按照一定命名规则批量修改多个文件的文件名的方法.   已知现有一个文件夹,其中包括班级所有同学上交的作业文件,每人一份:所有作业文件命名格式统一,都是地信1701_姓 ...