I'm encountering an issue when trying to build my Rust project using cargo build
. The build fails with the following error:
error: linking with `cc` failed: exit code: 1
...
undefined reference to `JNI_CreateJavaVM`
The build works fine if I delete main.rs
, but fails when it's present. I suspect the issue might be related to how Cargo.toml
is configured, particularly whether the project is recognized as a library or a binary.
Steps to Reproduce:
-
Clone the repository:
git clone https://github.com/kouhe3/rust-jni-glue.git
-
Checkout the specific commit:
git checkout d61d94d33e30b273ba5eb87aa0809bc9774f051f
-
Run
cargo build
Expected Behavior:
The project should compile successfully without errors, even with main.rs
present.
Actual Behavior:
The build fails with the undefined reference to JNI_CreateJavaVM
error.
Additional Context:
-
The project uses JNI (Java Native Interface) and attempts to interact with Java VM.
-
The
Cargo.toml
might not be correctly configured for JNI dependencies or linking. -
Deleting
main.rs
allows the build to succeed, suggesting the issue is specific to the binary entry point.
Questions:
-
Is there a misconfiguration in
Cargo.toml
that prevents proper linking of JNI symbols? -
How can I ensure
cargo build
correctly identifies the project type (binary or library) and links the necessary JNI dependencies? -
Are there additional steps required to properly integrate JNI in Rust projects?
Any guidance or suggestions would be greatly appreciated!