// 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

最新文章

  1. div高度根据内容自动增大
  2. xcode6.3插件失效
  3. IPv4 地址分类
  4. Unix安装BerkeleyDB
  5. webservice未能加载文件或程序集“**.DLL”或它的某一个依赖项。
  6. IntelliJ IDEA 14
  7. STM8S学习笔记-时钟控制2
  8. 转载:mybatis和hibernate 解析
  9. Sencha Touch 2 结合HTML5的本地存储创建数据库实现增、删、改、查
  10. Jmeter连接DB2/ORACLE/MYSQL数据库
  11. Ubantu16.04系统优化
  12. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
  13. 《HelloGitHub》第 36 期
  14. (转)ceph 常用 运维命令--查看信息 - 不错的文档
  15. int 与 Integer 的区别
  16. MS SQL Server 增删改查
  17. java web 项目中 简单定时器实现 Timer
  18. poj3009 Curling 2.0(很好的题 DFS)
  19. CSS图片两端对齐,自适应列表布局末行对齐修复实例页面
  20. 安装SQLserver2008r2出现 试图执行未经授权的操作

热门文章

  1. Js生成图片验证码
  2. 【集成开发环境 (IDE)】Dev-Cpp下载与安装 [ 图文教程 ]
  3. C++ 编译依赖管理系统分析以及 srcdep 介绍
  4. P5687 [CSP-S2019 江西] 网格图
  5. (18)go-micro微服务ELK介绍
  6. 解决微信小程序 自定义tabBar 切换时候闪烁问题
  7. 为啥要对jvm做优化?
  8. 【分析笔记】Linux 4.9 backlight 子系统分析
  9. Flink1.15仅支持ZooKeeper3.5/3.6
  10. Pytest插件pytest-order指定用例顺序