I am striving to find a simple (hello world-like, really) example of using Z3 bindings (z3.h) in plain C. My primary concern is solving equations (or rather systems thereof) so what I need to see is mainly declaring a variable, setting an assertion, checking, and finally retrieving a variable value.
I am aware of the Z3 example on GitHub but at over 3000 lines it is hardly minimalistic, plus it does not even provide a Makefile and a naïve compile with gcc does not work either.
I have been resorting to generating SMT2 code from my C program instead, and running it through z3 in command line, but I'd like to be able to use the bindings. For example this very simple equation: how would I set it up in a C program?
(declare-const x Real) (assert (= (+ (* x 4) 4) 20)) (check-sat) (get-value (x))
Apologies, for providing a non
ANSI-Canswer early on.I generated this by asking ChatGPT to convert the other example to ANSI-C and to replace
z3++.hwithz3.h. This time it required several iterations, and a walk throughgdb, to fix bugs it introduced.Check it is
ANSI-Cwith option-std=c89: