gpt4 book ai didi

android - 在 x86_64 上使用 x86_64 NDK 工具链链接失败

转载 作者:行者123 更新时间:2023-11-29 08:31:14 25 4
gpt4 key购买 nike

我正在使用 Android NDK 工具链为 32/64 位 ARM 和 x86 构建一个库。该库是用 Rust 编写的,我使用 clang 作为链接器。我正在使用 Android NDK default toolchains让我的 Makefile 工作。在所有平台上编译工作正常,x86_64 除外。我在 x86_64 Linux 上编译,但在 Mac OSX 上遇到同样的问题。我得到的错误如下:

error: linking with `x86_64-linux-android21-clang` failed: exit code: 1
|
= note: "x86_64-linux-android21-clang" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/x86_64-unknown-linux-gnu/release/deps/cryptobox-f7e54e68993dbdc8.0.o" "-o" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/x86_64-unknown-linux-gnu/release/deps/libcryptobox-f7e54e68993dbdc8.so" "-Wl,--version-script=/tmp/rustc.QEOguYgk4mJf/list" "-Wl,--gc-sections" "-Wl,-O1" "-nodefaultlibs" "-L" "../../libsodium-android-x86_64/lib" "-L" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/x86_64-unknown-linux-gnu/release/deps" "-L" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/release/deps" "-L" "\"./libs\"" "-L" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "-l" "sodium" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/x86_64-unknown-linux-gnu/release/deps/libcryptobox-9b6f2a0a353ba6df.rlib" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/x86_64-unknown-linux-gnu/release/deps/libproteus-40e6a130b38468f5.rlib" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/x86_64-unknown-linux-gnu/release/deps/libcbor-024d9926f0739f39.rlib" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/x86_64-unknown-linux-gnu/release/deps/libbyteorder-30acb91327072c30.rlib" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/x86_64-unknown-linux-gnu/release/deps/libhkdf-971b9da845836207.rlib" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/x86_64-unknown-linux-gnu/release/deps/libsodiumoxide-eccd1814def93cba.rlib" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/x86_64-unknown-linux-gnu/release/deps/liblibsodium_sys-f96178cc67fea277.rlib" "/home/calum/code/cryptobox-jni/android/build/src/cryptobox-v1.1.1/target/x86_64-unknown-linux-gnu/release/deps/liblibc-e8bd7a8d60e9ed01.rlib" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-13f36e2630c2d79b.rlib" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-3b9d178f1de89528.rlib" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-93bb403c9fc56f72.rlib" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-a2ef7979b4b3e1d5.rlib" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-d22754c8c52de3a1.rlib" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-c53f99154bf815c4.rlib" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_unicode-1cc5fcd37568ebc4.rlib" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_system-17a71bb92a82956c.rlib" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-739908a2e215dd88.rlib" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-3f4289353c600297.rlib" "/home/calum/.rustup/toolchains/1.16.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-07bfb3bcb2a51da0.rlib" "-l" "sodium" "-l" "util" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-shared" "-Wl,-soname,libcryptobox.so"
= note: /opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: cannot find -lutil
/opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: cannot find -lrt
/opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: cannot find -lpthread
/opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: cannot find -lgcc_s
/opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: cannot find -lpthread
/opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: cannot find -lrt
/opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: cannot find -lutil
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Makefile 的相关部分是:

jni/x86_64/libcryptobox.so: libsodium | build/src/$(CRYPTOBOX_NAME)
cd build/src/$(CRYPTOBOX_NAME) && \
export PATH="${PATH}:${TOOLCHAIN}/bin" && \
cargo rustc --lib --release --target=x86_64-unknown-linux-gnu -- \
-L ../../libsodium-android-x86_64/lib \
-l sodium \
-C ar=x86_64-linux-android-ar \
-C linker=x86_64-linux-android21-clang \
-C link_args="-Wl,-soname,libcryptobox.so"

其余的Makefile可以查看here .为什么只有 x86_64 在采购 pthread 和其他库时有问题?是否假设您将为主机平台使用“ native ”编译,而不是尝试使用 NDK 进行“交叉编译”?

此外,“--as-needed”标志从何而来?我没有在 Makefile 的 link_args 中指定它。我对 Rust 和与 Android 的交叉编译还很陌生,所以我什至不确定生成此标志的是 rust、clang 还是 NDK。关于此的一些建议也很有用,因为此标志导致构建在 MacOS 上失败,其中不支持“--as-needed”。

最佳答案

这个问题是我在调用 Rust 时使用了错误的目标造成的。我使用的是 x86_64-unknown-linux-gnu,因为我认为 x86_64 Android 没有目标。但是,确实有 x86_64-linux-android,但您必须选择最新的 rust 编译器版本作为默认版本,以便在搜索时看到此目标。对于旧的 rust 编译器版本(例如 1.16.0),它不存在。选择正确的目标后,编译工作。

关于android - 在 x86_64 上使用 x86_64 NDK 工具链链接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57166218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com