Build 7-Zip from Source with GCC or MSVC
Building 7-Zip directly from raw source code allows you to create
tailored binaries, optimize performance for specific CPU architectures,
and inspect code for security compliance. This guide explains how to
compile the official 7-Zip standalone console version (7zz)
from scratch using either the Microsoft Visual C++ (MSVC) compiler on
Windows or the GNU Compiler Collection (GCC) on Linux.
1. Download and Extract the Source Code
- Download the latest source code archive (e.g.,
7zXXXX-src.tar.xzor7zXXXX-src.7z) from the official 7-Zip distribution. - Extract the archive into a dedicated directory:
On Windows, extract using an existing 7-Zip installation or file archiver.
tar -xf 7z*-src.tar.xz -C 7zip-src cd 7zip-src
2. Building with MSVC on Windows
7-Zip provides NMake-compatible makefiles for the Visual C++ toolchain.
Prerequisites
- Visual Studio (or Visual Studio Build Tools) with the "Desktop development with C++" workload installed.
Compilation Steps
- Open the x64 Native Tools Command Prompt for VS.
- Navigate to the
Alone2directory, which builds the unified standalone console version:cd CPP\7zip\Bundles\Alone2 - Run
nmakewhile specifying the architecture:(For 32-bit x86 builds, usenmake CPU=AMD64nmake CPU=x86inside the x86 Native Tools Command Prompt). - Once compilation finishes, the resulting
7zz.exebinary will be located inside the generated output directory:b\c\x64\7zz.exe
3. Building with GCC on Linux / POSIX
Modern official 7-Zip releases include native makefiles tailored for GCC on POSIX platforms.
Prerequisites
gcc,g++, andmakeinstalled (e.g., viasudo apt install build-essentialon Debian/Ubuntu).
Compilation Steps
- Open a terminal and navigate to the
Alone2bundle directory:cd CPP/7zip/Bundles/Alone2 - Invoke
makeusing the bundled GCC makefile configuration:To build using parallel jobs for faster compilation, append themake -f ../../cmpl_gcc.mak-jflag:make -f ../../cmpl_gcc.mak -j$(nproc) - After compilation completes, the compiled executable
7zzis located in the target directory:./b/g/7zz
4. Verification
Run the generated binary without arguments to verify that the compile process was successful and to confirm the version number:
- Windows:
b\c\x64\7zz.exe - Linux:
./b/g/7zz
The terminal will display the 7-Zip banner along with the supported compression formats and available command-line switches.