Skip to content

Fix Java UnsatisfiedLinkError on macOS (#7640)#9027

Open
levnach wants to merge 1 commit intomasterfrom
fix-java-macos-unsatisfied-link-error-7640
Open

Fix Java UnsatisfiedLinkError on macOS (#7640)#9027
levnach wants to merge 1 commit intomasterfrom
fix-java-macos-unsatisfied-link-error-7640

Conversation

@levnach
Copy link
Copy Markdown
Contributor

@levnach levnach commented Mar 18, 2026

On macOS, libz3java.dylib was built without an rpath to find libz3.dylib in the same directory. When Java loaded the JNI library, the dynamic linker could not resolve the libz3 dependency, causing UnsatisfiedLinkError.

Three fixes:

  • mk_util.py: add -Wl,-rpath,@loader_path to the macOS JNI link command
  • CMakeLists.txt: set MACOSX_RPATH, BUILD_RPATH, INSTALL_RPATH for z3java target; remove duplicate headerpad block
  • update_api.py: improve Native.java error message to show the root cause from both load attempts instead of only the fallback error

On macOS, libz3java.dylib was built without an rpath to find
libz3.dylib in the same directory. When Java loaded the JNI library,
the dynamic linker could not resolve the libz3 dependency, causing
UnsatisfiedLinkError.

Three fixes:
- mk_util.py: add -Wl,-rpath,@loader_path to the macOS JNI link command
- CMakeLists.txt: set MACOSX_RPATH, BUILD_RPATH, INSTALL_RPATH for
  z3java target; remove duplicate headerpad block
- update_api.py: improve Native.java error message to show the root
  cause from both load attempts instead of only the fallback error

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@levnach
Copy link
Copy Markdown
Contributor Author

levnach commented Mar 18, 2026

@sabrieker, can you please review this pull request? This is an AI generated request and I am not an expert here.

@NikolajBjorner
Copy link
Copy Markdown
Contributor

@levnach - the PR adds functions to a file test_jni_...
I don't see references to this file elsewhere.
For build validation there is a workflow nightly-validation.yml.
It would be more systematic to include validation steps that are relevant into this workflow.
The workflow also currently fails for a reason I haven't diagnosed well (made initial stabs with copilot to poke at it).
Can you formulate precisely and assign to copilot to take care of nightly-validation and checking for issues such as this?

@levnach
Copy link
Copy Markdown
Contributor Author

levnach commented Mar 22, 2026

@NikolajBjorner, the file is here test_jni_arch_flags.py.

~/dev/z3/scripts/tests % git log test_jni_arch_flags.py
commit 6a1aa79 (origin/copilot/fix-jni-bindings-architecture)
Author: copilot-swe-agent[bot] 198982749+Copilot@users.noreply.github.com
Date: Mon Mar 9 16:28:12 2026 +0000

test: add unit tests and CI validation for JNI architecture fix

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>.

I will look at nightly-validation.yml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants