You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过API获取Leptonica版本及检查已安装版本

查询Leptonica版本的两种方法

嘿,刚好对Leptonica的版本查询比较熟悉,给你分两种场景详细说下:

1. 在代码中通过Leptonica API获取版本

Leptonica本身提供了两种方式在程序里获取版本信息:

预定义宏(编译时获取)

头文件<leptonica/allheaders.h>里已经定义了几个版本相关的宏,直接用就行:

  • LIBLEPT_MAJOR_VERSION:主版本号
  • LIBLEPT_MINOR_VERSION:次版本号
  • LIBLEPT_PATCH_VERSION:补丁版本号

示例代码:

#include <stdio.h>
#include <leptonica/allheaders.h>

int main() {
    printf("Leptonica 编译时版本: %d.%d.%d\n",
           LIBLEPT_MAJOR_VERSION,
           LIBLEPT_MINOR_VERSION,
           LIBLEPT_PATCH_VERSION);
    return 0;
}

运行时函数调用

如果你需要获取运行时链接的Leptonica库版本,可以用getLeptonicaVersion()函数,它会返回一个包含完整版本信息的字符串:

示例代码:

#include <stdio.h>
#include <leptonica/allheaders.h>

int main() {
    const char* version = getLeptonicaVersion();
    printf("Leptonica 运行时版本: %s\n", version);
    return 0;
}

2. 检查系统中已安装的Leptonica版本

根据你的操作系统不同,方法也不一样:

Linux 系统

  • 用pkg-config查询(最通用):
    pkg-config --modversion lept
    
  • Debian/Ubuntu 系列:
    dpkg -l | grep leptonica
    
  • RedHat/CentOS 系列:
    rpm -q leptonica
    

macOS 系统

如果是用Homebrew安装的:

brew info leptonica

或者用pkg-config(如果安装了的话):

pkg-config --modversion lept

Windows 系统

  • 如果是用vcpkg安装的:
    vcpkg list leptonica
    
  • 手动安装的话,可以查看安装目录下的leptonica/allheaders.h文件,里面能找到版本宏定义;或者看库文件的属性(比如liblept.dll的详细信息)。

内容的提问来源于stack exchange,提问作者clarkk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:40:33