Prerequisites
- Visual Studio 2019 or later (recommended for C++20 support)
- Python (for build configuration with mk_make.py)
- CMake 3.16+ (for CMake-based builds)
Z3 uses C++20, so Visual Studio 2019 or later is recommended for full language support.
Quick Start with Command Line
Open Developer Command Prompt
Launch the “Developer Command Prompt for Visual Studio” or “x64 Native Tools Command Prompt” from the Start menu.
Using Visual Studio IDE with CMake
Visual Studio 2019+
Visual Studio 2019 and later have integrated CMake support:Open the Z3 folder
In Visual Studio, select File → Open → Folder and navigate to the Z3 repository root directory.
Configure CMake
Visual Studio will automatically detect
CMakeLists.txt and begin configuration. You can customize CMake options in CMakeSettings.json.Select build configuration
Choose your build configuration (Debug, Release, etc.) from the dropdown in the toolbar.
Legacy Visual Studio Versions
For older Visual Studio versions, use CMake GUI:Configure paths
- Set “Where is the source code” to the Z3 repository root
- Set “Where to build the binaries” to your empty build directory
Configure the project
- Click Configure
- Select your Visual Studio version as the generator
- Choose platform (Win32 for 32-bit, x64 for 64-bit)
- Click Finish
Security Features (MSVC)
When building with MSVC, Z3 enables several security features by default to protect against exploitation:Control Flow Guard (CFG)
Enabled by default - Control Flow Guard protects against control flow hijacking attacks:- Compiler flag:
/guard:cf - Linker flag:
/GUARD:CF - Purpose: Validates indirect call targets at runtime to prevent attackers from redirecting control flow
With Python Build System
Disable if needed:With CMake
Disable if needed:Control Flow Guard is enabled by default on MSVC builds and provides important security hardening.
Address Space Layout Randomization (ASLR)
Automatically enabled with Control Flow Guard:- Linker flag:
/DYNAMICBASE - Purpose: Randomizes memory addresses to make exploitation more difficult
- Note: Required for Control Flow Guard to function
Incompatibilities
Control Flow Guard is incompatible with:/ZI- Edit and Continue debug information format/clr- Common Language Runtime compilation
Build Configurations
With Python Script (nmake)
With CMake and NMake
Ninja is recommended over NMake for significantly faster builds.
With CMake and Ninja
Ninja is much faster than NMake:Language Bindings
.NET Bindings
Build with .NET support:Z3 also provides a NuGet package at nuget.org/packages/Microsoft.Z3.
Python Bindings
Build inside the Visual C++ native command prompt:Java Bindings
Static vs Shared Library
Static Library (default)
Shared Library (DLL)
Visual Studio Generator Selection
When using CMake GUI, select the appropriate generator:| Generator | Architecture | Visual Studio Version |
|---|---|---|
| Visual Studio 17 2022 | x64 | VS 2022 (64-bit) |
| Visual Studio 17 2022 | Win32 | VS 2022 (32-bit) |
| Visual Studio 16 2019 | x64 | VS 2019 (64-bit) |
| Visual Studio 16 2019 | Win32 | VS 2019 (32-bit) |
| Visual Studio 15 2017 Win64 | x64 | VS 2017 (64-bit) |
| Visual Studio 15 2017 | Win32 | VS 2017 (32-bit) |
Generators with “Win64” in the name indicate 64-bit builds. Without it, they’re 32-bit builds.
CMake Configuration Options
Common options for Visual Studio builds:Multi-Configuration Builds
Visual Studio is a multi-configuration generator - you don’t set the build type when running CMake:Installation
Install to a specific location:Troubleshooting
C++20 Errors
Ensure you’re using Visual Studio 2019 or later:Python Not Found
Add Python to your PATH or specify the full path:Missing DLL at Runtime
Ensurelibz3.dll is in your PATH or in the same directory as the executable:
Control Flow Guard Warnings
If you see CFG incompatibility warnings, either:- Disable Edit and Continue (use
/Ziinstead of/ZI) - Disable Control Flow Guard:
-DZ3_ENABLE_CFG=OFF
CMake Can’t Find Visual Studio
Run CMake from the Developer Command Prompt, or specify the generator explicitly:Build Performance
Parallel Builds
With nmake (single-threaded), consider using Ninja instead:Incremental Builds
Ninja provides much faster incremental builds than NMake:Next Steps
- Learn about CMake builds for cross-platform development
- See Make builds for Unix-like systems
- Explore Bazel builds for advanced scenarios
