webassembly003 whisper.cpp的main项目-4 一些宏定义细节

标记函数为已弃用宏:WHISPER_DEPRECATED

  • 对于 GNU 编译器(__GNUC__),使用 __attribute__((deprecated(hint))) 属性将函数标记为已弃用,并附带指定的提示信息。
  • 对于微软 Visual C++ 编译器(_MSC_VER),使用 __declspec(deprecated(hint)) 属性实现相同的目的。
  • 对于其他编译器,函数不会被标记为已弃用。
cpp 复制代码
// 检查是否为 GNU 编译器
#ifdef __GNUC__
    // 对于 GNU 编译器,使用 __attribute__((deprecated(hint))) 将函数标记为已弃用
    // hint 参数用于提供关于已弃用的提示信息
    #define WHISPER_DEPRECATED(func, hint) func __attribute__((deprecated(hint)))
// 检查是否为 Microsoft Visual C++ 编译器
#elif defined(_MSC_VER)
    // 对于 Microsoft Visual C++ 编译器,使用 __declspec(deprecated(hint)) 将函数标记为已弃用
    // hint 参数用于提供关于已弃用的提示信息
    #define WHISPER_DEPRECATED(func, hint) __declspec(deprecated(hint)) func
// 其他编译器
#else
    // 对于其他编译器,不进行已弃用标记
    #define WHISPER_DEPRECATED(func, hint) func
#endif

使用示例

  • whisper_init_from_file_no_state 函数标记为已弃用,并建议使用 whisper_init_from_file_with_params_no_state 函数代替。

    复制代码
      WHISPER_DEPRECATED(
          WHISPER_API struct whisper_context * whisper_init_from_file_no_state(const char * path_model),
          "use whisper_init_from_file_with_params_no_state instead"
      );

WHISPER_API

cpp 复制代码
// 如果定义了 WHISPER_SHARED
#ifdef WHISPER_SHARED
    // 如果目标平台为 Windows(_WIN32)
    #ifdef _WIN32
        // 如果是构建共享库(WHISPER_BUILD 已定义)
        #ifdef WHISPER_BUILD
            // 定义 WHISPER_API 为 __declspec(dllexport)(导出符号)
            #define WHISPER_API __declspec(dllexport)
        // 如果是使用共享库(WHISPER_BUILD 未定义)
        #else
            // 定义 WHISPER_API 为 __declspec(dllimport)(导入符号)
            #define WHISPER_API __declspec(dllimport)
        #endif
    // 如果目标平台不是 Windows
    #else
        // 定义 WHISPER_API 为 __attribute__ ((visibility ("default")))(设置可见性为默认)
        #define WHISPER_API __attribute__ ((visibility ("default")))
    #endif
// 如果未定义 WHISPER_SHARED
#else
    // 定义 WHISPER_API 为空
    #define WHISPER_API
#endif
  • 注:宏定义使用 #define 关键字,定义 WHISPER_API 为空时(#define WHISPER_API),由于编译器在预处理阶段会将这些宏的出现替换为相应的代码或值。定义为空即什么也不做。

__declspec(dllimport) 和 __declspec(dllexport)

__declspec(dllimport)

  1. 作用

    • 用于标记在外部 DLL 中定义的函数或变量,表示这些函数或变量将在运行时从 DLL 中导入到当前模块(通常是可执行文件或其他 DLL)中使用。
  2. 示例

    cpp 复制代码
    // 在可执行文件或其他 DLL 中使用的声明
    __declspec(dllimport) void myFunction();
    __declspec(dllimport) int myVariable;

__declspec(dllexport)

  1. 作用

    • 用于标记在当前模块中定义的函数或变量,表示这些函数或变量将在运行时导出到 DLL 中,以便其他模块可以使用。
  2. 示例

    cpp 复制代码
    // 在 DLL 中定义的导出函数和变量
    __declspec(dllexport) void myFunction() {
        // 函数体
    }
    __declspec(dllexport) int myVariable = 42;

使用示例

复制代码
WHISPER_API struct whisper_context * whisper_init_from_file(const char * path_model);
相关推荐
六点_dn7 小时前
RabbitMQ学习笔记-部署和使用
笔记·学习·rabbitmq
2501_926978338 小时前
以说明书 DNA 为模板——完整 AGI 的结构图景
前端·人工智能·经验分享·笔记·ai写作
天天爱吃肉82188 小时前
商用车多体动力学实战笔记|第6篇:动力传动系统(发动机、变速箱、分动器、TCS、LSD限滑差速)
大数据·人工智能·笔记·python·嵌入式硬件·汽车
IT19959 小时前
Dify 实战笔记:工作流核心玩法 + 开源 AI 应用全解析
笔记
dong1326979 小时前
Agent Skills学习笔记
笔记·学习
摇滚侠11 小时前
《SpringBoot 3:入门与应用实战》第 15 章 生产级特性 管理 Spring Boot 应用 阅读笔记
java·spring boot·笔记
liferecords11 小时前
阅读笔记:ExtractBench: A Benchmark for Schema-Guided Enterprise Document Extraction
笔记
尤乐娃子12 小时前
进入大厂(厂子大)实习Day8
前端·笔记·实习
一只小菜鸡..12 小时前
南京大学 操作系统 (JYY) 学习笔记:持久化的黑魔法——从磁铁、刻坑到闪存电荷
服务器·笔记·学习
aFakeProgramer12 小时前
Linux版本兼容问题及RTA-VRTE环境配置笔记
linux·笔记