The reason, why Stockfish builds (and other C++ based chess engines), compiled on Termux, only runs in Termux environment and not outside (e. g. DroidFish) is simple. Stockfish is missing the libc++ runtime library, which is present in the Termux environment, but not in Android. Therefore you have to include the libc++ runtime library as a static part. This can be done by adding "-static-libstdc++" (the name "libstdc++" is for historical reasons and works also for libc++) to your linker flags (LDFLAGS). When there is an error like "lc++_shared is missing", clang needs the information , where to find the library, e. g. by using the flag --sysroot. But this doesn't work for me. As a quick and dirty solution you can also install ndk-multilib ("apt-get install ndk-multilib") which contains the necessary libraries.
With this changes, Android builds, compiled on Termux, also works on DroidFish and other GUIs.
Compiling Stockfish with the clang compiler on Termux can be done in three simple steps.
1. Download the sources.
Code: Select all
git clone https://github.com/official-stockfish/Stockfish
cd Stockfish/src
2. Add -static-libstdc++ to your linker flags in the makefile which is used by the clang compiler, for example in line 399:
Code: Select all
LDFLAGS += -m$(bits) -static-libstdc++
3. Compile Stockfish (from within the src directory).
Code: Select all
make -j profile-build ARCH=armv8 COMP=clang
PGO optimization seems to be only 1 %, maybe 2 % faster than the version without PGO (tested on Termux with the bench command from Stockfish). Not a big deal.
This is the way, how Stockfish can be compiled with the clang compiler on Termux. A description, on how it can be done with the gcc compiler may follow.