The Z3 Go bindings provide a comprehensive interface to Z3’s C API using CGO. The bindings are included in the Z3 source repository and must be built from source.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Z3Prover/z3/llms.txt
Use this file to discover all available pages before exploring further.
Requirements
Go
- Go 1.20 or later
- CGO enabled (default)
Build Tools
- C/C++ compiler (gcc, clang, or MSVC)
- CMake 3.4+ or Python 3.x
- Git
Build Z3 with Go Bindings
The Go bindings must be built as part of the Z3 library.Method 1: CMake (Recommended)
Method 2: Python Build System
Set Up Go Environment
After building Z3, configure your Go environment to use the bindings.Linux / macOS
~/.bashrc or ~/.zshrc for permanent configuration:
~/.bashrc
macOS Specific
On macOS, useDYLD_LIBRARY_PATH instead:
Windows
Using Go Modules
The Z3 Go bindings use Go modules. Your project should reference the Z3 repository:go.mod
go.mod
The
replace directive points to your local Z3 build since the Go bindings are not published to a Go module registry.Using in Your Code
main.go
Verification
Test your installation:test.go
Installation Options
System-Wide Installation
To install Z3 system-wide:LD_LIBRARY_PATH:
Static Linking
For static linking, build Z3 as a static library:Troubleshooting
undefined reference to Z3_* errors
undefined reference to Z3_* errors
Problem: Linker can’t find Z3 library.Solution:
- Verify
CGO_LDFLAGSincludes-L/path/to/build -lz3 - Check that
libz3.soexists in the build directory - On Linux: Run
sudo ldconfigafter system install - On Windows: Ensure
z3.dllis in PATH
z3.h: No such file or directory
z3.h: No such file or directory
Problem: Compiler can’t find Z3 headers.Solution:
- Verify
CGO_CFLAGSincludes-I/path/to/z3/src/api - Check that
z3.hexists insrc/api/z3.h
cannot find package
cannot find package
Problem: Go can’t find the Z3 package.Solution:
- Check your
go.modhas the correctreplacedirective - Verify the path points to
z3/src/api/go(not justz3) - Run
go mod tidy
shared library error at runtime
shared library error at runtime
CGO not enabled
CGO not enabled
Problem: CGO is disabled.Solution:
Build fails on macOS
Build fails on macOS
Problem: XCode command line tools or compiler missing.Solution:
Docker Setup
Use Docker for isolated development:Dockerfile
Platform-Specific Notes
- Linux
- macOS
- Windows
Most Linux distributions work out of the box with gcc/g++.Install dependencies:
Next Steps
Getting Started
Learn the basics with examples
API Reference
Complete API documentation
Examples
Example programs on GitHub
Build Guide
Detailed build instructions
