Skip to main content
7-Zip can be compiled on Linux using GCC or Clang compilers, with optional assembler optimizations for better performance.

Requirements

Compiler

GCC 4.8 or later (GCC 9+ recommended)
gcc --version
Install on Debian/Ubuntu:
sudo apt-get install build-essential

Build Tools

sudo apt-get install make

Assembler (Optional, for Performance)

For x86/x64 optimizations, install one of:
JWasm is not recommended - It doesn’t support AES instructions used in 7-Zip. The build will fall back to C versions of AES code, reducing performance.

Quick Start

Navigate to a bundle directory and build:
1

Navigate to Bundle

cd CPP/7zip/Bundles/Alone2
2

Build with make

make -j -f makefile.gcc
The -j flag enables parallel compilation for faster builds.
3

Run the binary

./b/g/7zz

Build Configurations

7-Zip provides specialized makefiles for optimized builds:

Basic Builds (No Assembler)

cd CPP/7zip/Bundles/Alone2
make -j -f ../../cmpl_gcc.mak

Optimized Builds (With Assembler)

cd CPP/7zip/Bundles/Alone2
make -j -f ../../cmpl_gcc_x64.mak

Makefile Variables

You can customize builds using variables with makefile.gcc:

Platform Control

IS_X64
boolean
default:"0"
Build for x86-64 architecture
make -f makefile.gcc IS_X64=1
USE_ASM
boolean
default:"0"
Enable assembler optimizations
make -f makefile.gcc IS_X64=1 USE_ASM=1
MY_ASM
string
default:"asmc"
Specify assembler program
make -f makefile.gcc IS_X64=1 USE_ASM=1 MY_ASM=/path/to/uasm

RAR Support Control

DISABLE_RAR
boolean
default:"0"
Remove all RAR-related code
make -f makefile.gcc DISABLE_RAR=1
DISABLE_RAR_COMPRESS
boolean
default:"0"
Remove RAR decompression codecs (keeps archive listing support)
make -f makefile.gcc DISABLE_RAR_COMPRESS=1

Assembler Selection

USE_JWASM
boolean
default:"0"
Use JWasm instead of Asmc (not recommended)
make -f makefile.gcc USE_JWASM=1
When using USE_JWASM=1, AES code from AesOpt.c will be used instead of assembler AesOpt.asm because JWasm doesn’t support AES instructions.

Build Examples

Standard x64 Build Without Assembler

cd CPP/7zip/Bundles/Alone2
make -j -f ../../cmpl_gcc.mak
Output: b/g/7zz

Optimized x64 Build With Assembler

cd CPP/7zip/Bundles/Alone2
make -j -f ../../cmpl_gcc_x64.mak
Output: b/g_x64/7zz

Build Without RAR Support

cd CPP/7zip/Bundles/Alone2
make -j -f ../../cmpl_gcc.mak DISABLE_RAR=1

Build With Custom UASM Assembler

UASM="$PWD/uasm"
cd CPP/7zip/Bundles/Alone2
make -f makefile.gcc -j IS_X64=1 USE_ASM=1 MY_ASM="$UASM"

Build Targets

Different bundle directories produce different binaries:
DirectoryOutputDescription
Bundles/Alone27zzStandalone binary (all formats)
Bundles/Alone7zaStandalone binary (limited formats)
Bundles/Alone7z7zrStandalone binary (7z only)
Bundles/Format7zF7z.soShared library (all formats)
UI/Console7zConsole binary (requires shared lib)

Compiler Flags

The build system uses the following optimization flags (from 7zip_gcc.mak):
CFLAGS_BASE = -O2 -Wall -Wextra -Werror \
  -D_REENTRANT -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
  -fPIC
Additional optimization options:
  • -flto - Link-time optimization (enabled in some configs)
  • -ffunction-sections - Separate functions for linker optimization

Output Directory Structure

Builds create output in subdirectories:
  • b/g/ - GCC builds (general)
  • b/g_x64/ - GCC x64 builds
  • b/g_arm64/ - GCC ARM64 builds
  • _o/ - Default output directory for makefile.gcc

Troubleshooting

If building with USE_ASM=1 but assembler is missing:
# Either install assembler
git clone https://github.com/nidud/asmc

# Or build without assembler
make -j -f ../../cmpl_gcc.mak
Install pthread development libraries:
sudo apt-get install libpthread-stubs0-dev
Use the -j flag to enable parallel compilation:
make -j$(nproc) -f makefile.gcc

Performance Comparison

Builds with assembler optimizations provide significant performance improvements:
With Assembler (cmpl_gcc_x64.mak):
  • Optimized CRC32 calculation
  • Hardware AES encryption (if CPU supports)
  • Faster LZMA compression/decompression
  • Optimized SHA-256 hashing
Without Assembler (cmpl_gcc.mak):
  • Uses C implementations for all codecs
  • Portable to any architecture
  • Slower but still functional

Cross-Compilation

To cross-compile for a different architecture:
export CROSS_COMPILE=aarch64-linux-gnu-
make -f makefile.gcc -j
The var_gcc.mak file supports the CROSS_COMPILE variable for setting the compiler prefix.

Next Steps

  • Test your build: ./b/g/7zz --help
  • Benchmark performance: ./b/g/7zz b
  • Review build options

See Also

Build docs developers (and LLMs) love