Contents

swiftytesseract/libtesseract

This repo contains build scripts to compile [Tesseract](https://github.com/tesseract-ocr/tesseract) and it's dependencies for Apple platforms to be distributed as a Swift package. It's primary goal is to aid in migrating [SwiftyTesseract](https://github.com/SwiftyTesseract/Swifty

Installation

Add libtesseract as a Swift Package Dependency

// Package.swift
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription

let package = Package(
  name: "AwesomePackage",
  platforms: [
    // These are the minimum versions libtesseract supports
    .macOS(.v10_13),
    .iOS(.v11),
  ],
  products: [
    .library(
      name: "AwesomePackage",
      targets: ["AwesomePackage"]
    ),
  ],
  dependencies: [
    .package(url: "https://github.com/SwiftyTesseract/libtesseract.git", from: "0.2.0")
  ],
  targets: [
    .target(
      name: "AwesomePackage",
      dependencies: ["libtesseract"],
      linkerSettings: [.linkedLibrary("z"), .linkedLibrary("c++")]
    ),
  ]
)

// AwesomePackage.swift
import libtesseract

Additional Required Configuration

You must link against the following libraries:

  • libc++
  • libz

This can be done in an Xcode-based project by adding these in Build Phases -> Link Binary with Libaries [screenshot of xcode linking libc++ and libz]

In a Swift Package Manager project, this can be achieved by adding the following to your target linkerSettings:

// See Package.swift example above for full context
  targets: [
    .target(
      name: "AwesomePackage",
      dependencies: ["libtesseract"],
      linkerSettings: [.linkedLibrary("z"), .linkedLibrary("c++")]
    ),
  ]

See SwiftyTesseract's Additonal Configuration notes on considerations for including language training data files.

Build dependencies

If you want to build libtesseract from source, you need automake, pkg-config, and task installed on your machine. These can be installed via homebrew:

brew install automake pkg-config go-task/tap/go-task

To build a library for distribution run task build-tesseract-xcframework-zip

Attributions

libtesseract disributes the following dependencies in binary form:

Package Metadata

Repository: swiftytesseract/libtesseract

Default branch: main

README: README.md