Skip to content
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

x86_64 linker issue #122

Closed
NiallBunting opened this issue Oct 21, 2023 · 7 comments
Closed

x86_64 linker issue #122

NiallBunting opened this issue Oct 21, 2023 · 7 comments

Comments

@NiallBunting
Copy link

NiallBunting commented Oct 21, 2023

I'm running the command:
cargo ndk -o ./android -t armeabi-v7a -t x86_64 build
The armeabi builds correctly but I run into a linker issue with the x86_64 build.

Completing with = note: ld.lld: error: unable to find library -lclang_rt.builtins-x86_64-android clang-17: error: linker command failed with exit code 1 (use -v to see invocation)
The full output is here: https://pastebin.com/sgbyYEUh

I checked NDK to see if that builtin exists and it seems to be here:
/home/nib/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/17/lib/linux/libclang_rt.builtins-x86_64-android.a.

Also ensured that rustup was correct:
nib@nib-desktop:~/repos/matrix-rust-sdk/bindings/matrix-sdk-ffi$ rustup target install x86_64-linux-android info: component 'rust-std' for target 'x86_64-linux-android' is up to date.

@igor-brishkoski

This comment was marked as off-topic.

@bbqsrc
Copy link
Owner

bbqsrc commented Oct 28, 2023

I checked NDK to see if that builtin exists and it seems to be here: /home/nib/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/17/lib/linux/libclang_rt.builtins-x86_64-android.a.

Builds correctly for me on macOS with NDK v26.0.10792818, so I suspect the NDK is doing nonsensical things again, or you need to update your cargo-ndk.

@bbqsrc
Copy link
Owner

bbqsrc commented Oct 29, 2023

@NiallBunting this is an issue with matrix-rust-sdk. You need to set NDK_CLANG_VERSION to the clang version relative to the NDK you're targetting. See their build.rs file.

@bbqsrc bbqsrc closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2023
@igor-brishkoski
Copy link

Not sure why you closed this, seems other people are having the same issue with different libraries.

tauri-apps/tauri#6047

@bbqsrc
Copy link
Owner

bbqsrc commented Oct 30, 2023

This has nothing to do with cargo-ndk and everything to do with not linking to the correct libraries.

@NiallBunting
Copy link
Author

Ah I think it might actually be caused by this: rust-lang/rust#109717

@9p4
Copy link

9p4 commented May 20, 2024

Made some changes to matrix-rust-sdk to get this working:

diff --git a/bindings/matrix-sdk-crypto-ffi/build.rs b/bindings/matrix-sdk-crypto-ffi/build.rs
index a3572f17f..39663cab2 100644
--- a/bindings/matrix-sdk-crypto-ffi/build.rs
+++ b/bindings/matrix-sdk-crypto-ffi/build.rs
@@ -18,13 +18,16 @@ fn setup_x86_64_android_workaround() {
                 "Unsupported OS. You must use either Linux, MacOS or Windows to build the crate."
             ),
         };
-        const DEFAULT_CLANG_VERSION: &str = "14.0.7";
+        const DEFAULT_CLANG_VERSION: &str = "17";
+        const DEFAULT_NDK_VERSION: &str = "26.3.11579264";
         let clang_version =
             env::var("NDK_CLANG_VERSION").unwrap_or_else(|_| DEFAULT_CLANG_VERSION.to_owned());
+        let ndk_version =
+            env::var("NDK_VERSION").unwrap_or_else(|_| DEFAULT_NDK_VERSION.to_owned());
         let linux_x86_64_lib_dir = format!(
-            "toolchains/llvm/prebuilt/{build_os}-x86_64/lib64/clang/{clang_version}/lib/linux/"
+            "toolchains/llvm/prebuilt/{build_os}-x86_64/lib/clang/{clang_version}/lib/linux/"
         );
-        println!("cargo:rustc-link-search={android_ndk_home}/{linux_x86_64_lib_dir}");
+        println!("cargo:rustc-link-search={android_ndk_home}/{ndk_version}/{linux_x86_64_lib_dir}");
         println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
     }
 }
diff --git a/bindings/matrix-sdk-ffi/build.rs b/bindings/matrix-sdk-ffi/build.rs
index e22f54451..217b28750 100644
--- a/bindings/matrix-sdk-ffi/build.rs
+++ b/bindings/matrix-sdk-ffi/build.rs
@@ -18,13 +18,16 @@ fn setup_x86_64_android_workaround() {
                 "Unsupported OS. You must use either Linux, MacOS or Windows to build the crate."
             ),
         };
-        const DEFAULT_CLANG_VERSION: &str = "14.0.7";
+        const DEFAULT_CLANG_VERSION: &str = "17";
+        const DEFAULT_NDK_VERSION: &str = "26.3.11579264";
         let clang_version =
             env::var("NDK_CLANG_VERSION").unwrap_or_else(|_| DEFAULT_CLANG_VERSION.to_owned());
+        let ndk_version =
+            env::var("NDK_VERSION").unwrap_or_else(|_| DEFAULT_NDK_VERSION.to_owned());
         let linux_x86_64_lib_dir = format!(
-            "toolchains/llvm/prebuilt/{build_os}-x86_64/lib64/clang/{clang_version}/lib/linux/"
+            "toolchains/llvm/prebuilt/{build_os}-x86_64/lib/clang/{clang_version}/lib/linux/"
         );
-        println!("cargo:rustc-link-search={android_ndk_home}/{linux_x86_64_lib_dir}");
+        println!("cargo:rustc-link-search={android_ndk_home}/{ndk_version}/{linux_x86_64_lib_dir}");
         println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
     }
 }

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

No branches or pull requests

4 participants