Skip to main content
The Z3 C API is the core interface to Z3 and is automatically included with all Z3 distributions. All other language bindings are built on top of the C API.

Prerequisites

  • C compiler (GCC, Clang, MSVC, or compatible)
  • CMake (optional, for building from source)
  • Python 3.x (for building from source)

Installation Options

Download the latest Z3 release for your platform from the GitHub Releases page.
wget https://github.com/Z3Prover/z3/releases/download/z3-x.x.x/z3-x.x.x-x64-glibc-x.x.zip
unzip z3-x.x.x-x64-glibc-x.x.zip
cd z3-x.x.x-x64-glibc-x.x

# Copy headers and libraries to system directories
sudo cp include/*.h /usr/local/include/
sudo cp bin/libz3.so /usr/local/lib/
sudo ldconfig
The pre-built binaries include:
  • include/z3.h - Main C API header
  • include/z3_*.h - Additional API headers
  • bin/libz3.so (Linux) / bin/libz3.dylib (macOS) / bin/libz3.dll (Windows) - Shared library

Option 2: Build from Source

Building from source gives you the latest features and allows customization.
git clone https://github.com/Z3Prover/z3.git
cd z3
python scripts/mk_make.py
cd build
make
sudo make install

Option 3: Package Managers

sudo apt-get install libz3-dev

Verify Installation

Create a test file test_z3.c:
test_z3.c
#include <stdio.h>
#include <z3.h>

int main() {
    Z3_config cfg = Z3_mk_config();
    Z3_context ctx = Z3_mk_context(cfg);
    Z3_del_config(cfg);
    
    unsigned major, minor, build, revision;
    Z3_get_version(&major, &minor, &build, &revision);
    printf("Z3 version: %u.%u.%u.%u\n", major, minor, build, revision);
    
    Z3_del_context(ctx);
    return 0;
}
Compile and run:
gcc test_z3.c -o test_z3 -lz3
./test_z3
Expected output:
Z3 version: 4.x.x.x

Linking with Z3

GCC/Clang

gcc your_program.c -o your_program -lz3
If Z3 is installed in a non-standard location:
gcc your_program.c -o your_program -I/path/to/z3/include -L/path/to/z3/lib -lz3

CMake

Add to your CMakeLists.txt:
find_package(Z3 REQUIRED)
target_link_libraries(your_target PRIVATE z3::libz3)

Visual Studio

  1. Add include directory: Project Properties → C/C++ → General → Additional Include Directories: C:\z3\include
  2. Add library directory: Project Properties → Linker → General → Additional Library Directories: C:\z3\bin
  3. Add library: Project Properties → Linker → Input → Additional Dependencies: libz3.lib

Runtime Configuration

Linux/macOS

If Z3 is not installed in a standard location, set LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (macOS):
export LD_LIBRARY_PATH=/path/to/z3/lib:$LD_LIBRARY_PATH

Windows

Ensure libz3.dll is in your PATH or in the same directory as your executable.

Troubleshooting

Header Not Found

fatal error: z3.h: No such file or directory
Solution: Add the Z3 include directory to your compiler’s include path using -I.

Library Not Found

/usr/bin/ld: cannot find -lz3
Solution: Add the Z3 library directory using -L or install Z3 to a standard location.

Runtime Library Error

error while loading shared libraries: libz3.so: cannot open shared object file
Solution: Set LD_LIBRARY_PATH or run sudo ldconfig after installation.

Next Steps

Getting Started

Learn the basics of the Z3 C API

API Reference

Explore the complete C API documentation

Build docs developers (and LLMs) love