Compiling for Android

Moderators: Elijah, Igbo, timetraveller

superbatil
Forum Contributions
Points: 14 010,00 
Posts: 76
Joined: 24/02/2022, 11:23
Status: Offline (Active 2 Weeks, 6 Hours, 31 Minutes ago)
Topics: 0
Reputation: 17
Has thanked: 1 time
Been thanked: 51 times

Re: Compiling for Android

Post by superbatil »

Archimedes wrote: 01/12/2022, 10:27 In bitbase.cpp add

Code: Select all

#include "globals.h"
and in globals.cpp make the following modification:

Code: Select all

// #include "bitbase.cpp"
After that another problem occured.

Code: Select all

WARNING: linker: /data/data/com.termux/files/home/opt/android-ndk-r24/toolchains/llvm/prebuilt/linux-aarch64/bin/clang-14: unsupported flags DT_FLAGS_1=0x8000001
In file included from /data/data/com.termux/files/home/arasan-chess/jni/../src/topo.cpp:2:  /data/data/com.termux/files/home/arasan-chess/jni/../src/topo.h:11:10: fatal error: 'hwloc.h' file not found
#include <hwloc.h>                                     ^~~~~~~~~
1 error generated.                            make: *** [/data/data/com.termux/files/home/opt/android-ndk-r24/build/core/build-binary.mk:424: /data/data/com.termux/files/home/arasan-chess/obj/local/arm64-v8a/objs/Arasan/__/src/topo.o] Error 1
Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Online (Active 2 Hours, 37 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

Why are you compiling a file that isn't even necessary? Look in the makefile and you will see, what files are necessary. If you use wildcards for compilation, then you have to delete the unneeded files that cause problems first. For successful compilation, you must first delete the following files:

Code: Select all

topo.cpp
tune.cpp
tuner.cpp
superbatil
Forum Contributions
Points: 14 010,00 
Posts: 76
Joined: 24/02/2022, 11:23
Status: Offline (Active 2 Weeks, 6 Hours, 31 Minutes ago)
Topics: 0
Reputation: 17
Has thanked: 1 time
Been thanked: 51 times

Re: Compiling for Android

Post by superbatil »

Archimedes wrote: 05/12/2022, 10:54 Why are you compiling a file that isn't even necessary? Look in the makefile and you will see, what files are necessary. If you use wildcards for compilation, then you have to delete the unneeded files that cause problems first. For successful compilation, you must first delete the following files:

Code: Select all

topo.cpp
tune.cpp
tuner.cpp
I'm sorry I didn't study coding but I just observed. Thank you very much and I have learned something new.
superbatil
Forum Contributions
Points: 14 010,00 
Posts: 76
Joined: 24/02/2022, 11:23
Status: Offline (Active 2 Weeks, 6 Hours, 31 Minutes ago)
Topics: 0
Reputation: 17
Has thanked: 1 time
Been thanked: 51 times

Re: Compiling for Android Bluefish Nnue

Post by superbatil »

Why this error occur?

Code: Select all

misc.cpp:624:12: error: use of undeclared identifier '_mm_malloc'
        void* p = _mm_malloc(size, align);
                  ^
1 error generated.
make[2]: *** [<builtin>: misc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/data/data/com.termux/files/home/Bluefish NNUE/src'
make[1]: *** [Makefile:507: clang-profile-make] Error 2
make[1]: Leaving directory '/data/data/com.termux/files/home/Bluefish NNUE/src'
make: *** [Makefile:426: profile-build] Error 2
Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Online (Active 2 Hours, 37 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android Bluefish Nnue

Post by Archimedes »

superbatil wrote: 05/12/2022, 17:20 Why this error occur?

Code: Select all

misc.cpp:624:12: error: use of undeclared identifier '_mm_malloc'
        void* p = _mm_malloc(size, align);
                  ^
1 error generated.
make[2]: *** [<builtin>: misc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/data/data/com.termux/files/home/Bluefish NNUE/src'
make[1]: *** [Makefile:507: clang-profile-make] Error 2
make[1]: Leaving directory '/data/data/com.termux/files/home/Bluefish NNUE/src'
make: *** [Makefile:426: profile-build] Error 2
Difficult to say without source code. Seems to be an Intel method. wink

https://www.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/intrinsics/data-align-mem-alloc-intrins-and-inline-asmbly/allocating-and-freeing-aligned-memory-blocks.html
superbatil
Forum Contributions
Points: 14 010,00 
Posts: 76
Joined: 24/02/2022, 11:23
Status: Offline (Active 2 Weeks, 6 Hours, 31 Minutes ago)
Topics: 0
Reputation: 17
Has thanked: 1 time
Been thanked: 51 times

Re: Compiling for Android

Post by superbatil »

Sir Archinedes,
I would like to know what is the config in rust for compiling to armv8? "Walleye chess engine"
Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Online (Active 2 Hours, 37 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

superbatil wrote: 15/01/2023, 14:46 Sir Archinedes,
I would like to know what is the config in rust for compiling to armv8? "Walleye chess engine"
What do you mean with config? The parameters that were used during compilation?
superbatil
Forum Contributions
Points: 14 010,00 
Posts: 76
Joined: 24/02/2022, 11:23
Status: Offline (Active 2 Weeks, 6 Hours, 31 Minutes ago)
Topics: 0
Reputation: 17
Has thanked: 1 time
Been thanked: 51 times

Re: Compiling for Android

Post by superbatil »

Archimedes wrote: 16/01/2023, 10:05
superbatil wrote: 15/01/2023, 14:46 Sir Archinedes,
I would like to know what is the config in rust for compiling to armv8? "Walleye chess engine"
What do you mean with config? The parameters that were used during compilation?
yes..
Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Online (Active 2 Hours, 37 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

That's easy to answer. :smile:

See Cargo.toml file. I used the following entry.

Code: Select all

[profile.release]
opt-level = 3
lto = true
debug = false
codegen-units = 1
In the meantime, however, I use the following entry for all compilations with Rust.

Code: Select all

[profile.release]
opt-level = 3
lto = true
debug = false
codegen-units = 1
strip = true
superbatil
Forum Contributions
Points: 14 010,00 
Posts: 76
Joined: 24/02/2022, 11:23
Status: Offline (Active 2 Weeks, 6 Hours, 31 Minutes ago)
Topics: 0
Reputation: 17
Has thanked: 1 time
Been thanked: 51 times

Re: Compiling for Android

Post by superbatil »

Compiling on Walleye got problem about linker or command mimalloc on rust from android.

Code: Select all

~/Walleye $ cargo build --release
    Updating crates.io index
   Compiling libc v0.2.139
   Compiling cc v1.0.78
   Compiling log v0.4.17
   Compiling cfg-if v1.0.0
   Compiling lazy_static v1.4.0
   Compiling unicode-width v0.1.10
   Compiling ansi_term v0.11.0
   Compiling vec_map v0.8.2
   Compiling bitflags v1.3.2
   Compiling textwrap v0.11.0
   Compiling rand_core v0.6.4
   Compiling strsim v0.8.0
   Compiling ppv-lite86 v0.2.17
   Compiling rand_chacha v0.3.1
   Compiling libmimalloc-sys v0.1.30
   Compiling atty v0.2.14
   Compiling thread-id v3.3.0
   Compiling colored v2.0.0
   Compiling clap v2.33.4
   Compiling simple-logging v2.0.2
   Compiling mimalloc v0.1.34
   Compiling walleye v1.6.0 (/data/data/com.termux/files/home/Walleye)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "/data/data/com.termux/files/usr/tmp/rustcx6uNIQ/symbols.o" "/data/data/com.termux/files/home/Walleye/target/release/deps/walleye-735ec141551295a4.walleye.80605549-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/data/data/com.termux/files/home/Walleye/target/release/deps" "-L" "/data/data/com.termux/files/home/Walleye/target/release/build/libmimalloc-sys-3f3582e2eb3a35ba/out" "-L" "/data/data/com.termux/files/usr/lib/rustlib/aarch64-linux-android/lib" "-Wl,-Bstatic" "/data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib" "/data/data/com.termux/files/usr/lib/rustlib/aarch64-linux-android/lib/libcompiler_builtins-51d7c0e4340f2e85.rlib" "-Wl,-Bdynamic" "-ldl" "-llog" "-lunwind" "-ldl" "-lm" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/data/data/com.termux/files/usr/lib/rustlib/aarch64-linux-android/lib" "-o" "/data/data/com.termux/files/home/Walleye/target/release/deps/walleye-735ec141551295a4" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-Wl,-O1" "-nodefaultlibs"
  = note: ld.lld: error: undefined symbol: __aarch64_ldadd8_relax
          >>> referenced by static.c
          >>>               static.o:(mi_stats_reset) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(mi_stats_reset) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(mi_stats_reset) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced 183 more times

          ld.lld: error: undefined symbol: __aarch64_cas8_rel
          >>> referenced by static.c
          >>>               static.o:(mi_stats_reset) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(mi_os_mem_alloc) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(mi_os_mem_alloc) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced 82 more times

          ld.lld: error: undefined symbol: __emutls_get_address
          >>> referenced by static.c
          >>>               static.o:(mi_stats_reset) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(_mi_os_alloc_huge_os_pages) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(_mi_malloc_generic) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced 20 more times

          ld.lld: error: undefined symbol: __aarch64_cas8_acq_rel
          >>> referenced by static.c
          >>>               static.o:(mi_os_mem_alloc) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(_mi_os_alloc_huge_os_pages) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(_mi_bitmap_try_find_from_claim_pred) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced 41 more times

          ld.lld: error: undefined symbol: __aarch64_ldadd8_acq_rel
          >>> referenced by static.c
          >>>               static.o:(_mi_warning_message) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(_mi_error_message) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(mi_manage_os_memory_ex) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced 7 more times

          ld.lld: error: undefined symbol: __aarch64_ldclr8_acq_rel
          >>> referenced by static.c
          >>>               static.o:(_mi_bitmap_try_find_from_claim_pred) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(_mi_arena_free) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(_mi_arena_free) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced 8 more times

          ld.lld: error: undefined symbol: __aarch64_swp8_acq_rel
          >>> referenced by static.c
          >>>               static.o:(_mi_arena_free) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(_mi_arena_free) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(_mi_abandoned_reclaim_all) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced 21 more times

          ld.lld: error: undefined symbol: __aarch64_ldset8_acq_rel
          >>> referenced by static.c
          >>>               static.o:(mi_manage_os_memory_ex) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(mi_segment_cache_purge) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced by static.c
          >>>               static.o:(mi_arena_alloc_from) in archive /data/data/com.termux/files/usr/tmp/rustcx6uNIQ/liblibmimalloc_sys-c3e49541c3a900c6.rlib
          >>> referenced 7 more times
          clang-15: error: linker command failed with exit code 1 (use -v to see invocation)


error: could not compile `walleye` due to previous error
Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Online (Active 2 Hours, 37 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

Probably you have not defined the linker. Install Android NDK and define the appropriate linker (for example /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang). And by the way, which operating system are we talking about?
superbatil
Forum Contributions
Points: 14 010,00 
Posts: 76
Joined: 24/02/2022, 11:23
Status: Offline (Active 2 Weeks, 6 Hours, 31 Minutes ago)
Topics: 0
Reputation: 17
Has thanked: 1 time
Been thanked: 51 times

Re: Compiling for Android

Post by superbatil »

Archimedes wrote: 17/01/2023, 9:24 Probably you have not defined the linker. Install Android NDK and define the appropriate linker (for example /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang). And by the way, which operating system are we talking about?
The operating system I use is Android phone nougat and then it uses termux.
Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Online (Active 2 Hours, 37 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

I can write you a recipe for cross compiling under Linux. This should also work in Termux. Should I do that?
superbatil
Forum Contributions
Points: 14 010,00 
Posts: 76
Joined: 24/02/2022, 11:23
Status: Offline (Active 2 Weeks, 6 Hours, 31 Minutes ago)
Topics: 0
Reputation: 17
Has thanked: 1 time
Been thanked: 51 times

Re: Compiling for Android

Post by superbatil »

Archimedes wrote: 17/01/2023, 10:09 I can write you a recipe for cross compiling under Linux. This should also work in Termux. Should I do that?
yes yes yes. thanks.
Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Online (Active 2 Hours, 37 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

I am by no means a specialist in the Rust programming language. I compile under Debian GNU/Linux, which means I do cross compiling. So I can only offer you a recipe for cross compiling under Linux.

I assume that you have already installed Android NDK (for example in the directory /opt/android-ndk).

After installing the Rust compiler, you need to install the following targets.

Code: Select all

rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
rustup target add i686-linux-android
rustup target add x86_64-linux-android
After that you have to create a file named "config" in the home directory under .cargo with the following content:

.cargo/config:

Code: Select all

[target.aarch64-linux-android]
linker = "/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang"

[target.armv7-linux-androideabi]
linker = "/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi19-clang"

[target.i686-linux-android]
linker = "/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android19-clang"

[target.x86_64-linux-android]
linker = "/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android21-clang"
These are the definitions for the linker to be used.

You then compile for the different architectures using the following commands.

Code: Select all

cargo build --release --target=aarch64-linux-android
cargo build --release --target=armv7-linux-androideabi
cargo build --release --target=i686-linux-android
cargo build --release --target=x86_64-linux-android
Post Reply

Return to “Programming, Technical Discussions, Chess related questions etc.”