zoukankan      html  css  js  c++  java
  • 导出符号

    1. 好处

    • 提升DSO(dynamic shared object)加载时间
    • 让优化器产生更好的代码。
    • 减小DSO大小
    • 降低符号冲突的可能

    2. 常用写法

    libhv

    #if defined(_MSC_VER)
        #if defined(HV_DYNAMICLIB) || defined(HV_EXPORTS) || defined(hv_EXPORTS)
            #define HV_EXPORT  __declspec(dllexport)
        #else
            #define HV_EXPORT  __declspec(dllimport)
        #endif
    #elif defined(__GNUC__)
        #define HV_EXPORT  __attribute__((visibility("default")))
    #else
        #define HV_EXPORT
    #endif
    

    gcc wiki

    #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
    public:
       Person(int _c) : c(_c) { }
       static void foo(int a);
    };
    

    3. 参考

    1. https://gcc.gnu.org/wiki/Visibility
    2. https://akkadia.org/drepper/dsohowto.pdf
  • 相关阅读:
    Linux磁盘与文件系统操作命令
    Linux 进程管理命令
    文件备份与压缩命令
    Linux系统命令
    CentOS6和CentOS7的区别
    nginx安装配置
    docker的容器和镜像的清理
    Zabbix-Agent配置文件详解
    k8s 获取登录token命令
    vmware 端口转发设置
  • 原文地址:https://www.cnblogs.com/suntus/p/15260531.html
Copyright © 2011-2022 走看看