-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JNI_GetCreatedJavaVMs #14
Comments
Could you add a complete minimal example? |
it doesn't work for me neither here is a example [dependencies]
jni = { version = "0.21.1", features = ["invocation"] }
toy-arms = { git = "https://github.com/pseuxide/toy-arms" }
[lib]
crate-type = ["cdylib"] use std::slice;
use toy_arms::internal;
internal::create_entrypoint!(client);
fn client() {
unsafe {
let vms = get_created_java_vms().unwrap();
let mut _jvm;
for vm in vms {
match jni::JavaVM::from_raw(vm) {
Ok(java_vm) => _jvm = java_vm,
Err(_) => println!("Failed to create jvm"),
};
}
};
}
unsafe fn get_created_java_vms() -> Result<Vec<*mut jni::sys::JavaVM>, String> {
let vm_buf: *mut *mut jni::sys::JavaVM = std::ptr::null_mut();
let buf_len: jni::sys::jsize = 0;
let mut n_vms: jni::sys::jsize = 0;
let result = jni::sys::JNI_GetCreatedJavaVMs(vm_buf, buf_len, &mut n_vms);
if result != 0 {
return Err(format!(
"JNI_GetCreatedJavaVMs failed with error code {}",
result
));
}
if buf_len < n_vms {
return Err(format!(
"Buffer length ({}) is smaller than the number of VMs ({})",
buf_len, n_vms
));
}
let vms: Vec<_> = slice::from_raw_parts(vm_buf, n_vms as usize).to_vec();
Ok(vms)
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using this i get linker errors.
The code which i used
error
error: linking with
link.exe
failed: exit code: 1120|
= note: "E:\Applications\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\link.exe" "/DEF:C:\Users\Luna\AppData\Local\Temp\rustc2LoRkl\lib.def" "/NOLOGO" "X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.1byzs9aaoeboij1f.rcgu.o" "X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.23idsa2h5m4re0n7.rcgu.o" "X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.2u6h2lnoz1tkqhvf.rcgu.o" "X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.3tbrj5df0601ijj4.rcgu.o" "X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.3wjcuz3qbx2gbnyl.rcgu.o" "X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.3x2g0e2hwqmehtp8.rcgu.o" "X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.57k2cudsxfgkp4pr.rcgu.o" "X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.6b40e381e4fagx6.rcgu.o" "X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.az2bwusxx6ld47f.rcgu.o" "X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.3q890reoho8keq5z.rcgu.o" "/LIBPATH:X:\meta\dev\rust\Shimakaze\target\debug\deps" "/LIBPATH:X:\meta\dev\rust\Shimakaze\target\debug\build\libudis86-sys-cf96a0ee695f5f98\out" "/LIBPATH:C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib" "X:\meta\dev\rust\Shimakaze\target\debug\deps\libwinapi-bb0ca2babfa2b4a5.rlib" "X:\meta\dev\rust\Shimakaze\target\debug\deps\libjni-1de0fc098823e7b5.rlib" "X:\meta\dev\rust\Shimakaze\target\debug\deps\libcesu8-a7f08aae99a2104d.rlib" "X:\meta\dev\rust\Shimakaze\target\debug\deps\liblog-97e4acb7b95be317.rlib" "X:\meta\dev\rust\Shimakaze\target\debug\deps\libcfg_if-b01931459ea167fc.rlib" "X:\meta\dev\rust\Shimakaze\target\debug\deps\libcombine-cbc02205a55fd8f3.rlib" "X:\meta\dev\rust\Shimakaze\target\debug\deps\libmemchr-665d2c8c4b4cfe12.rlib" "X:\meta\dev\rust\Shimakaze\target\debug\deps\libbytes-49090a364b4888f6.rlib" "X:\meta\dev\rust\Shimakaze\target\debug\deps\libthiserror-500c731b3379430b.rlib" "X:\meta\dev\rust\Shimakaze\target\debug\deps\libjni_sys-dd815645ea921445.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libstd-2915a6598b644f05.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libpanic_unwind-600ba5171389b19e.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libstd_detect-9551a16e5791cc07.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\librustc_demangle-9accc95c56c66c72.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libhashbrown-174e0bf43a687c69.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\librustc_std_workspace_alloc-c67793bd74cdc09e.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libunwind-f28b8bbd63ca4a61.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libcfg_if-4242b0a6ddf9db60.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\liblibc-5c6e234e3431724c.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\liballoc-ef0d43e84d25019c.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\librustc_std_workspace_core-665ed95809278e59.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libcore-c2100e40c13f915d.rlib" "C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libcompiler_builtins-9fa99e8814512f70.rlib" "advapi32.lib" "cfgmgr32.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "opengl32.lib" "user32.lib" "winspool.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "msvcrt.lib" "/NXCOMPAT" "/LIBPATH:C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib" "/OUT:X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.dll" "/OPT:REF,NOICF" "/DLL" "/IMPLIB:X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.dll.lib" "/DEBUG" "/NATVIS:C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\etc\intrinsic.natvis" "/NATVIS:C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\etc\liballoc.natvis" "/NATVIS:C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\etc\libcore.natvis" "/NATVIS:C:\Users\Luna\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\etc\libstd.natvis"
= note: Creating library X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.dll.lib and object X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.dll.exp
Shimakaze.23idsa2h5m4re0n7.rcgu.o : error LNK2019: unresolved external symbol JNI_GetCreatedJavaVMs referenced in function _ZN9Shimakaze10dll_attach17h80d4ba29a706405fE
X:\meta\dev\rust\Shimakaze\target\debug\deps\Shimakaze.dll : fatal error LNK1120: 1 unresolved externals
The text was updated successfully, but these errors were encountered: