rustlinkerandroid-ndkrust-cargo

Unable to find -lunwind library in Rust for Android target


I am creating a shared library for aarch64-linux-android target. After setting the linker to the linker provided by the android NDK and configuring the path to the prebuilt native android libraries using the -C link-args=--library-path=... flag in config.toml, I get this error during building:

ld: error: unable to find library -lunwind

I tried to set the --sysroot argument of the linker (which seems to do nothing). Also adding --Bdynamic isn't doing anything either.

Some insight on this would be helpful.


Solution

  • Apparently the issue was caused because the target.<triple>.linker was set as ...ndk/.../ld. I figured out that using ...ndk/.../<target_triple><sdk_version>-clang as the linker fixed all issues. You just have to specify the clang compiler as the linker and it works very well. There's no need to add any extra paths or set sysroot.