mk_make.py) to generate Makefiles, which are then used to compile Z3. This approach is simple and works well for Unix-like systems.
For building OCaml bindings, the Make-based system is required. For other use cases, CMake is recommended.
Prerequisites
- Python (for running
mk_make.py) - GCC or Clang compiler
- Make
- Git (optional)
Basic Build
Compiler Selection
By default,g++ is used if available. To use Clang:
Cross-Platform Builds
Windows with Cygwin and MinGW
You can build Z3 for Windows using Cygwin and the MinGW-w64 cross-compiler:Make sure to use Cygwin’s own Python, not a Windows installation of Python.
Installation Prefix
The default installation prefix varies by platform:- Linux:
/usr - FreeBSD/macOS:
/usr/local
- Binaries:
PREFIX/bin - Libraries:
PREFIX/lib - Headers:
PREFIX/include
Build Configuration Options
Language Bindings
Enable specific language bindings:Python Package Directory
For non-standard installation prefixes, specify the Python package directory:A better approach for non-standard prefixes is to use a Python virtual environment.
Using Virtual Environments
Install Z3 in a Python virtual environment:Architecture-Specific Builds
32-bit vs 64-bit
The build system automatically detects your system architecture. For Windows builds using the Visual Studio Command Prompt, you can explicitly specify: 32-bit build:Managing Builds
Cleaning
To clean the build, delete the build directory and regenerate:Uninstalling
Dependencies
Z3 has minimal dependencies:- C++ runtime libraries - including pthreads for multi-threading
- Python - required for build configuration
- GMP (optional) - for multi-precision integers (Z3 has built-in alternative)
Using GMP
To use the GNU Multiple Precision library instead of Z3’s built-in implementation:-DZ3_USE_LIB_GMP=ON
Platform-Specific Notes
Linux
Standard build works out of the box:macOS
Installs to/usr/local by default:
FreeBSD
Similar to macOS, installs to/usr/local:
Cygwin
For 64-bit builds from Cygwin64:Building Specific Components
OCaml Bindings
The Make build system is required for OCaml bindings:Go Bindings
Go bindings use CGO and require Go 1.20 or later:Common Use Cases
Development Build
Quick build for development:Production Build with Python
Optimized build with Python bindings:All Bindings
Build with all available bindings:Compiler Flags
Themk_make.py script handles most compiler flag configuration automatically. For custom flags, you can set environment variables:
Comparison with CMake
| Feature | Make Build | CMake Build |
|---|---|---|
| Configuration | Python script | CMake configuration |
| Ease of use | Very simple | More complex |
| OCaml bindings | ✓ Supported | ✗ Not supported |
| Multi-config | ✗ No | ✓ Yes (Visual Studio) |
| IDE integration | Limited | Excellent |
| Recommended for | OCaml, simple builds | Most use cases |
Troubleshooting
Python Not Found
Ensure Python is in your PATH:Compiler Not Found
Verify your compiler is installed and accessible:Permission Denied During Install
Usesudo for system-wide installation:
Build Failures
Clean and rebuild:Next Steps
- Learn about CMake builds for advanced configuration
- See Visual Studio builds for Windows development
- Explore Bazel builds for large-scale projects
