Linking with 'cc' failed (when trying to compile a simple 'hello_world' for Android terminal)

98 views Asked by At

I'm trying to test what an Android terminal application would be writing the simplest program (hello_world) in Rust. I have downloaded the Android NDK, which I have placed in ~/Android/Sdk/ndk/26.1.10909125. I have correctly set the path in ~/.bashrc. I think I also have configured Cargo.toml properly for my project. But still I'm getting this output when trying to build with: "cargo build --target arm-linux-androideabi".

This is my ~/.bashrc relative code:

export PATH=$PATH:/home/alberto/.platformio/penv/bin
export NDK_PATH=~/Android/Sdk/ndk/26.1.10909125/
export CC=$NDK_PATH/build/tools/make_standalone_toolchain.py
export CXX=$NDK_PATH/build/tools/make_standalone_toolchain.py


export PATH=$PATH:/usr/bin/cc/  # Adjust the path accordingly

. "$HOME/.cargo/env"

And this is the content of 'Cargo.toml':

[package]
name = "prueba_android"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build]
target = "arm-linux-androideabi"

[target.'cfg(target_os = "android")']
linker = "arm-linux-androideabi-gcc"
[target.armv7-linux-androideabi.dependencies]
openssl = { version = "*", features = ["vendored"] }

Finally, this is the error output when trying to build:

            Compiling prueba_android v0.1.0 (/home/alberto/dev/Rust/prueba_android)
error: linking with `cc` failed: exit status: 1
  |
      = note: LC_ALL="C" PATH="/home/alberto/.rustup/toolchains/stable-x86_64-unknown-    linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/alberto/.cargo/bin:/usr/local    /bin:/usr/bin:/bin:/usr/local/games:/usr/games:/sbin:/usr/sbin:/opt/nvim-linux64/bin:/home    /alberto/.platformio/penv/bin:/opt/youtube-dl/bin:/usr/bin/cc/" VSLANG="1033" "cc"     "/tmp/rustcC7JpHt/symbols.o" "/home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.1dly7hkg4gti9r2b.rcgu.o" "/home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.2os6eumlnpucp6xb.rcgu.o" "/home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.2v4101m5wgw07n3.rcgu.o" "/home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.31dxvgfiviwsf6bt.rcgu.o" "/home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.8zw0p8rd3dv341v.rcgu.o" "/home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.ifwavqqdns8993u.rcgu.o" "/home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.29tqpbq14ystttfq.rcgu.o" "-Wl,--as-needed" "-L" "/home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps" "-L" "/home/alberto/dev/Rust/prueba_android/target/debug/deps" "-L" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib" "-Wl,-Bstatic" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libstd-70dc02d4becdad39.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libpanic_unwind-fd7c97c7ce8b5336.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libobject-74c2ee7a93806fd7.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libmemchr-5534e05bf7c920f3.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libaddr2line-0b197b4c65125e94.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libgimli-59771ebcfdf2c2dd.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/librustc_demangle-9635835a292c18de.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libstd_detect-0055064e58824835.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libhashbrown-bfaa1da43e00d280.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/librustc_std_workspace_alloc-a6602e9a193df30f.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libminiz_oxide-f03adc9aafa8b743.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libadler-d6a63a2764b322f3.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libunwind-4bc9722cd5e08712.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libcfg_if-cbda85831d0c2720.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/liblibc-7684da15788e127f.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/liballoc-518fbe8e650611c6.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/librustc_std_workspace_core-e0c05e5f937860b2.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libcore-eae1c0fbe05a9966.rlib" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libcompiler_builtins-0485666037a5e815.rlib" "-Wl,-Bdynamic" "-ldl" "-llog" "-lunwind" "-ldl" "-lm" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/alberto/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib" "-o" "/home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: /usr/bin/ld: /home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.1dly7hkg4gti9r2b.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.1dly7hkg4gti9r2b.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.1dly7hkg4gti9r2b.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.1dly7hkg4gti9r2b.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.1dly7hkg4gti9r2b.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.1dly7hkg4gti9r2b.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.1dly7hkg4gti9r2b.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/alberto/dev/Rust/prueba_android/target/aarch64-linux-android/debug/deps/prueba_android-07bb52ebcba4a0d3.1dly7hkg4gti9r2b.rcgu.o: error adding symbols: file in wrong format
          collect2: error: ld returned 1 exit status
          

error: could not compile `prueba_android` (bin "prueba_android") due to previous error

Could you please help me out?

0

There are 0 answers