使用 NDK 编译为 Android 共享库时链接 Rust lib 时出现问题

问题描述 投票:0回答:1

构建为可执行文件 main.rs 而不是 lib.rs 时没有链接错误

错误: 与 C:/Users/nafan/AppData/Local/ndk/26.2.11394342/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android34-clang++.cmd 链接失败:退出代码:255

注意:--version-script=C:\Users afan\AppData\Local\Temp ustcfcjtoe\list"" 这时候出乎意料了

config.toml

[target.aarch64-linux-android]
ar = "C:/Users/nafan/AppData/Local/ndk/26.2.11394342/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android34-clang++"
linker = "C:/Users/nafan/AppData/Local/ndk/26.2.11394342/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android34-clang++.cmd"

Cargo.toml

[lib]
name = "renderer"
crate-type = ["cdylib"]

[dependencies]
jni = "0.21.1"

lib.rs

use jni::{objects::JClass, sys::jint, JNIEnv};

#[no_mangle]
pub extern "C" fn Java_com_example_myapp_RustInterface_rustFunction(_env: JNIEnv, _class: JClass) -> jint {
    let value = 42; // Example value

    // Convert the value to JNI jint and return it
    value as jint
} 

android android-ndk arm linker-errors rust-cargo
1个回答
0
投票

可能的解决方法是稍微更改 aarch64-linux-android34-clang++.cmd 内容

https://github.com/android/ndk/issues/1856#issuecomment-1542248775

© www.soinside.com 2019 - 2024. All rights reserved.