Requirements
OCaml
- OCaml 4.09.0 or later
- ocamlfind (findlib)
- opam (recommended)
Build Tools
- C/C++ compiler
- Python 3.x or CMake
- Git
Installation Methods
Method 1: Build from Source (Recommended)
Build Z3 with OCaml bindings from source.1
Clone Z3 Repository
2
Build with Python
The
--staticlib flag creates a static library, making binaries self-contained.3
Install with ocamlfind
- OCaml modules:
z3.cmi,z3.cmo,z3.cmx, etc. - Static library:
libz3-static.a - Libraries:
z3ml.{a,cma,cmxa,cmxs}
Method 2: OPAM (When Available)
Build Artifacts
The build process creates several files:OCaml Modules
files
Core Z3 module with type definitions and main API
files
Z3 enumeration types
files
Native bindings to Z3 C API
Libraries
library
Native code static library for
ocamloptlibrary
Bytecode library for
ocamlclibrary
Standalone shared library for dynamic loading with
Dynlinklibrary
C stubs archive
library
Shared object for OCaml runtime (bytecode)
library
Z3 library itself (when using
--staticlib)Compiling OCaml Programs
Using ocamlfind (Recommended)
The easiest way to compile programs using Z3:The
-thread flag is required for the Z3 bindings.Static Linking
With--staticlib, native binaries have no Z3 dependency:
Custom Bytecode (Self-Contained)
Create a portable bytecode executable:Manual Compilation
Without ocamlfind:Using in OCaml Toplevel
Load Z3 in the OCaml REPL:OCaml Scripts
Create executable OCaml scripts:script.ml
Dynamic Loading with Dynlink
Thez3ml.cmxs file can be dynamically loaded:
Verification
Test your installation:test.ml
Platform-Specific Notes
- Linux
- macOS
- Windows
Most distributions work out of the box:If using dynamic linking, ensure library path is set:
Troubleshooting
Cannot find package z3
Cannot find package z3
Problem: ocamlfind can’t locate Z3.Solution:
- Verify installation:
ocamlfind query z3 - Reinstall:
ocamlfind remove z3then reinstall - Check OPAM switch:
opam switch
Linking errors
Linking errors
Problem: Undefined references to Z3 symbols.Solution:
- Ensure
-threadflag is used - With dynamic linking, set
LD_LIBRARY_PATH - Use
--staticlibwhen building for self-contained binaries
DLL not found (bytecode)
DLL not found (bytecode)
Problem:
dllz3ml.so not found when running bytecode.Solution:- Install properly with ocamlfind (it handles stublibs)
- Or use
-customflag for self-contained bytecode - Check:
ocamlfind query -format '%d/stublibs' z3
Version mismatch
Version mismatch
Problem: OCaml module compiled with different Z3 version.Solution:
- Rebuild Z3 from source
- Clean build directory:
make cleanbefore rebuilding - Reinstall with ocamlfind
Advanced: Manual Installation Paths
If not using ocamlfind:Docker Setup
Use Docker for isolated environment:Dockerfile
Next Steps
Getting Started
Learn the basics with examples
Examples
Example programs on GitHub
API Documentation
OCaml API reference
Build Instructions
Detailed build guide
