// 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. uniapp 微信小程序 实现左侧菜单右侧列表,双向联动的效果

    <template> <view class="u-wrap"> <view class="u-search-box"> & ...

  2. 第七节 VOR/DME进近程序保护区的绘制

    飞行程序设计软件实践 通过前面六节的练习,2023社区版插件的主要功能都已经使用到了.今天通过VOR/DME非精密进近程序,再将这些功能串起来使用一下.今天的软件,我们使用浩辰CAD2023版(过期后 ...

  3. [深度学习]DEEP LEARNING(深度学习)学习笔记整理

    转载于博客http://blog.csdn.net/zouxy09 一.概述 Artificial Intelligence,也就是人工智能,就像长生不老和星际漫游一样,是人类最美好的梦想之中的一个. ...

  4. 从Babel开始认识AST抽象语法树

    前言 AST抽象语法树想必大家都有听过这个概念,但是不是只停留在听过这个层面呢.其实它对于编程来讲是一个非常重要的概念,当然也包括前端,在很多地方都能看见AST抽象语法树的影子,其中不乏有vue.re ...

  5. ResourceQuota与LimitRange区别

    ResourceQuota与LimitRange区别 ResourceQuota ResourceQuota 用来限制 namespace 中所有的 Pod 占用的总的资源 request 和 lim ...

  6. DOM的操作(增删改查)

    操作DOM的核心就是增删改查 目录 一.节点创建型API 1.1 createElement 1.2 createTextNode 1.3 cloneNode 1.4 createDocumentFr ...

  7. day12-实现Spring底层机制-02

    实现Spring底层机制-02 3.实现任务阶段1 3.1知识拓展-类加载器 Java的类加载器有三种: Bootstrap类加载器 ----- 对应路径 jre/lib Ext类加载器 ----- ...

  8. 应用容器引擎-Docker

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows操作系统的机器上,也可以实现虚拟化.容器是完全使用沙箱 ...

  9. php上传微信素材

    private function HttpsUpdateFileServerRequest($url,$path_img){ $curl = curl_init (); if (class_exist ...

  10. 数字游戏(NOIP 2003 PJT2)

    一 原始数据处理 1.输入数据得到a[1]~a[n],复制扩展a[n+1]~a[2*n],以便处理不同点为起点出发. cin>>n>>m; for(int i=1;i<= ...