Skip to content

Commit

Permalink
Specify and document value for environment variable for loading nativ…
Browse files Browse the repository at this point in the history
…e library in Java bindings (#5477)

* limit range of environment variable for loading the native library in Java to "true".

This change specifies the range of values that are allowed to set the environment
variable "z3.skipLibraryLoad".
Only the value "true" (in upper-, lower-, and mixed-case is accepted as valid value.
Other values, such as "false", "0", "1", "foo", an empty or a missing value are
evaluated to "false" and cause the default loading of the native library.

* adding documentation about environment variable for (not) loading the native library in Java.

This is a follow-up commit for #4667 to provide a publicly visible documentation.
  • Loading branch information
kfriedberger authored Aug 13, 2021
1 parent 35698c6 commit 764e033
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions examples/java/README
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ On Linux and FreeBSD, we must use
LD_LIBRARY_PATH=. java -cp com.microsoft.z3.jar:. JavaExample
On macOS, the corresponding option is DYLD_LIBRARY_PATH:
DYLD_LIBRARY_PATH=. java -cp com.microsoft.z3.jar:. JavaExample

By default, Z3 Java bindings are automatically loading the required native library for Z3 from the default library path.
In certain environments, depending on the developing process, the Z3 library is not available in the given library path.
To disable the automated loading process, the user can set the environment variable "z3.skipLibraryLoad=true".
In that case, the calling application should directly load the corresponding libraries before any interaction with Z3.

2 changes: 1 addition & 1 deletion scripts/update_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def mk_java(java_dir, package_name):
java_native.write(' public static native void setInternalErrorHandler(long ctx);\n\n')

java_native.write(' static {\n')
java_native.write(' if (null == System.getProperty("z3.skipLibraryLoad")) {\n')
java_native.write(' if (!Boolean.parseBoolean(System.getProperty("z3.skipLibraryLoad"))) {\n')
java_native.write(' try {\n')
java_native.write(' System.loadLibrary("z3java");\n')
java_native.write(' } catch (UnsatisfiedLinkError ex) {\n')
Expand Down

0 comments on commit 764e033

Please sign in to comment.