7-Zip C++ SDK for Embedding Compression

This article outlines the official C++ SDK provided by 7-Zip for integrating compression and decompression routines into custom software. It details the LZMA SDK, its architectural features, supported formats, integration methods, and licensing terms to help developers embed 7-Zip technology directly into their C++ applications.

The LZMA SDK

The official development kit provided by Igor Pavlov, the creator of 7-Zip, is the LZMA SDK (Lempel-Ziv-Markov chain Algorithm Software Development Kit). While commonly referred to as the 7-Zip SDK, it is distributed under the name LZMA SDK and provides the core compression algorithms and container handling used by the 7-Zip file archiver.

The SDK includes complete source code for:

  • LZMA and LZMA2: The primary compression algorithms providing high compression ratios and fast decompression.
  • 7z Format Handling: Code for creating and extracting .7z archive containers.
  • Supporting Algorithms: Implementation of BCJ/BCJ2 (filter for x86/ARM executables), Delta filters, and basic encryption/decryption routines.

Integration Methods for C++ Applications

Developers have two primary approaches when embedding the SDK into a C++ application:

1. Direct Source Code Integration

The SDK includes clean, self-contained ANSI C and C++ source files. For embedding raw LZMA or LZMA2 compression directly into memory buffers or custom file streams, developers can compile the SDK source files directly into their projects.

  • Advantages: No external runtime dependencies, minimal binary footprint, and cross-platform compatibility (Windows, Linux, macOS).
  • Common Files Used: LzmaEnc.c, LzmaDec.c, Alloc.c, and 7zCrc.c.

2. COM-Style Interface via 7z.dll

For full archive management—such as handling complex .7z, ZIP, TAR, or RAR archives—the SDK provides C++ headers that define Component Object Model (COM)-style interfaces. These interfaces allow applications to interact dynamically with 7z.dll (or 7za.dll).

  • Key Interfaces: IInArchive, IOutArchive, ISequentialInStream, and ISequentialOutStream.
  • Advantages: Access to the full suite of formats supported by 7-Zip without managing the underlying archive parsing code directly.

Licensing and Usage

One of the main advantages of the LZMA SDK is its permissive licensing model:

  • The core LZMA compression and decompression source code is placed in the Public Domain.
  • Parts of the code handling specific archive formats and complex filters are released under the GNU LGPL or common permissive open-source licenses.

Because the core code is in the public domain, developers can integrate 7-Zip's compression technology into both open-source and proprietary commercial applications without royalty fees or restrictive copyleft obligations.