How to setup a Java development environment for the Z3 SMT solver?
Note: Written and answered by the author, see Can I answer my own question? .
Z3 is a C++ application with Java bindings. Start by downloading the native distribution, Ubuntu in our case (similar approach should work for macOS), from https://github.com/Z3Prover/z3/releases , for example: z3-4.8.7-x64-ubuntu-16.04.zip
.
Unzip the build to a Z3_DIR
. To simplify things, have the following exports:
export Z3_DIR=<some_path>/z3-4.8.7-x64-ubuntu-16.04
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Z3_DIR/bin
$ curl https://raw.githubusercontent.com/Z3Prover/z3/z3-4.8.7/examples/java/JavaExample.java > JavaExample.java
$ javac -cp $Z3_DIR/bin/com.microsoft.z3.jar JavaExample.java
$ java -cp $Z3_DIR/bin/com.microsoft.z3.jar:. JavaExample
If all is well, you should see the example executing without errors.
$ mvn install:install-file \
-Dfile=$Z3_DIR/bin/com.microsoft.z3.jar \
-DgroupId=com.microsoft \
-DartifactId=z3 \
-Dversion=4.8.7 \
-Dpackaging=jar \
-DgeneratePom=true
A jar named z3-4.8.7.jar
will be created in <mavenrepo>/repository/com/microsoft/z3/4.8.7/
. It can be added to a maven project as dependency:
<dependency>
<groupId>com.microsoft</groupId>
<artifactId>z3</artifactId>
<version>4.8.7</version>
</dependency>
com/microsoft/z3
before registering them with an IDE. EDIT - macOS Unfortunately setting library path ( DYLD_LIBRARY_PATH
) on macOS doesn't work, for some details and a solution see here: https://github.com/Z3Prover/z3/issues/294
Z3-TurnKey是一个不错的项目,它发布了一个 Maven 工件,其中包含在运行时链接的 OS X、Windows 和 Linux 的预构建本机库。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.