Termux (Linux environment for Android)

Moderators: Elijah, Igbo, timetraveller

kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 8 Hours, 33 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Termux (Linux environment for Android)

Post by kramnik »

Yes: everythibg installed and upgraded

$ setupgcc-11
setupgcc-11: command not found
~ $ cd /data/data/com.termux/files/usr/lib/gcc/aarch64-linux-android
bash: cd: /data/data/com.termux/files/usr/lib/gcc/aarch64-linux-android: No such file or directory
~ $
Archimedes wrote: 12/10/2021, 13:59 Before doing anything else, do you have installed all updates on Termux?

Code: Select all

apt-get update
apt-get upgrade
Take a look at the /data/data/com.termux/files/usr/lib/gcc/aarch64-linux-android directory. What version of gcc do you see?
Archimedes

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

Re: Termux (Linux environment for Android)

Post by Archimedes »

In the home directory (when you start Termux) enter

Code: Select all

cd ..
and then

Code: Select all

cd usr/lib/gcc/aarch64-linux-android
and then

Code: Select all

ls
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 8 Hours, 33 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Termux (Linux environment for Android)

Post by kramnik »

~ $ cd ..
.../com.termux/files $ cd usr/lib/gcc/aarch64-linux-android
bash: cd: usr/lib/gcc/aarch64-linux-android: No such file or directory

Archimedes wrote: 12/10/2021, 14:31 In the home directory (when you start Termux) enter

Code: Select all

cd ..
and then

Code: Select all

cd usr/lib/gcc/aarch64-linux-android
and then

Code: Select all

ls
Archimedes

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

Re: Termux (Linux environment for Android)

Post by Archimedes »

Seems, gcc is not installed.

Code: Select all

apt-get install gcc-11
What messages do you get?
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 8 Hours, 33 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Termux (Linux environment for Android)

Post by kramnik »

Awesome, it's installed! But I can omly launch gcc-11... In order to be compliant with the Stockfish Makefile I must rename the binary to gcc, where can I find it?
Archimedes wrote: 12/10/2021, 19:55 Seems, gcc is not installed.

Code: Select all

apt-get install gcc-11
What messages do you get?
Archimedes

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

Re: Termux (Linux environment for Android)

Post by Archimedes »

Now, you must enter

Code: Select all

setupgcc-11
No need to rename anything.
Archimedes

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

Re: Termux (Linux environment for Android)

Post by Archimedes »

Afterwards you can check the version of gcc.

Code: Select all

gcc --version
As a first projekt, to see gcc is really working, compile the Demolito chess engine.

Code: Select all

git clone https://github.com/lucasart/Demolito
cd Demolito/src
make CC=gcc
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 8 Hours, 33 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Termux (Linux environment for Android)

Post by kramnik »

Code: Select all

~/Stockfish/src $ make -j build ARCH=x86-64
make: g++: No such file or directory
make: g++: No such file or directory
Default net: nn-13406b1dcbe0.nnue
Downloading https://tests.stockfishchess.org/api/nn/nn-13406b1dcbe0.nnue

Config:
debug: 'no'
sanitize: 'none'
optimize: 'yes'
arch: 'x86_64'
bits: '64'
kernel: 'Linux'
os: 'Android'
prefetch: 'yes'
popcnt: 'no'
pext: 'no'
sse: 'yes'
mmx: 'no'
sse2: 'yes'
ssse3: 'no'
sse41: 'no'
avx2: 'no'
avx512: 'no'
vnni256: 'no'
vnni512: 'no'
neon: 'no'

Flags:
CXX: g++
CXXFLAGS: -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp -DIS_64BIT -msse -DUSE_SSE2 -msse2 -flto -fPIE
LDFLAGS:  -m64 -Wl,--no-as-needed -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp -DIS_64BIT -msse -DUSE_SSE2 -msse2 -flto -fPIE -flto=jobserver -fPIE -pie

Testing config sanity. If this fails, try 'make help' ...

make ARCH=x86-64 COMP=gcc all
make[1]: Entering directory '/data/data/com.termux/files/home/Stockfish/src'
make[1]: g++: No such file or directory
make[1]: g++: No such file or directory
g++ -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp -DIS_64BIT -msse -DUSE_SSE2 -msse2 -flto -fPIE   -c -o benchmark.o benchmark.cpp
make[1]: g++: No such file or directory
make[1]: *** [<builtin>: benchmark.o] Error 127
make[1]: Leaving directory '/data/data/com.termux/files/home/Stockfish/src'
make: *** [Makefile:746: build] Error 2
~/Stockfish/src $ setupg++-11
setupg++-11: command not found
~/Stockfish/src $ setupg++
setupg++: command not found
~/Stockfish/src $ g++-11
g++-11: fatal error: no input files
compilation terminated.
~/Stockfish/src $
As I suspected: binaries have to be renamed. In this case from g++-11 to g++ .

Archimedes wrote: 13/10/2021, 5:09 Now, you must enter

Code: Select all

setupgcc-11
No need to rename anything.
Archimedes

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

Re: Termux (Linux environment for Android)

Post by Archimedes »

kramnik wrote: 06/10/2021, 21:45 That's why I wrote here. I was hoping for something from Skynet, as he did the procedure already, or some else developer.

I still can produce Android binaries both from Windows and Linux with clang, but he told that using gcc on Termux produces faster binaries.
Speed difference between clang and gcc (both installed on Termux) are about 6 % with DroidFish on my smartphone. Tested with Demolito. When i do an benchmark on Termux, the difference is smaller, may be less than 3 %. Regarding Stockfish, there is a speed difference of about 10 % between gcc (with PGO optimization) and Android NDK (clang, without PGO optimization). Results my differ on other devices.
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 8 Hours, 33 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Termux (Linux environment for Android)

Post by kramnik »

Found it! The binary is in the ../usr/bin folder.

Got these errors now: (most probably some missing library)

Code: Select all

g++ -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp -DIS_64BIT -msse -DUSE_SSE2 -msse2 -flto -fPIE   -c -o misc.o misc.cpp
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
g++ -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp -DIS_64BIT -msse -DUSE_SSE2 -msse2 -flto -fPIE   -c -o movegen.o movegen.cpp
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++ -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp -DIS_64BIT -msse -DUSE_SSE2 -msse2 -flto -fPIE   -c -o movepick.o movepick.cpp
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
make[1]: *** [<builtin>: bitbase.o] Error 1
make[1]: *** Waiting for unfinished jobs....
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-msse2'
make[1]: *** [<builtin>: evaluate.o] Error 1
make[1]: *** [<builtin>: benchmark.o] Error 1
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
make[1]: *** [<builtin>: material.o] Error 1
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse'
make[1]: *** [<builtin>: bitboard.o] Error 1
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
make[1]: *** [<builtin>: main.o] Error 1
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
make[1]: *** [<builtin>: movegen.o] Error 1
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
make[1]: *** [<builtin>: movepick.o] Error 1
make[1]: *** [<builtin>: endgame.o] Error 1
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
make[1]: *** [<builtin>: misc.o] Error 1
make[1]: Leaving directory '/data/data/com.termux/files/home/Stockfish/src'
make: *** [Makefile:746: build] Error 2
Archimedes

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

Re: Termux (Linux environment for Android)

Post by Archimedes »

kramnik wrote: 13/10/2021, 10:18 Found it! The binary is in the ../usr/bin folder.

Got these errors now: (most probably some missing library)

Code: Select all

g++ -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp -DIS_64BIT -msse -DUSE_SSE2 -msse2 -flto -fPIE   -c -o misc.o misc.cpp
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
g++ -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp -DIS_64BIT -msse -DUSE_SSE2 -msse2 -flto -fPIE   -c -o movegen.o movegen.cpp
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++ -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp -DIS_64BIT -msse -DUSE_SSE2 -msse2 -flto -fPIE   -c -o movepick.o movepick.cpp
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
make[1]: *** [<builtin>: bitbase.o] Error 1
make[1]: *** Waiting for unfinished jobs....
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-msse2'
make[1]: *** [<builtin>: evaluate.o] Error 1
make[1]: *** [<builtin>: benchmark.o] Error 1
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-mthumb'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-m64'
g++: error: unrecognized command-line option '-mthumb'
make[1]: *** [<builtin>: material.o] Error 1
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse'
make[1]: *** [<builtin>: bitboard.o] Error 1
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
make[1]: *** [<builtin>: main.o] Error 1
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
make[1]: *** [<builtin>: movegen.o] Error 1
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse2'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
make[1]: *** [<builtin>: movepick.o] Error 1
make[1]: *** [<builtin>: endgame.o] Error 1
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-msse'
g++: error: unrecognized command-line option '-msse2'
make[1]: *** [<builtin>: misc.o] Error 1
make[1]: Leaving directory '/data/data/com.termux/files/home/Stockfish/src'
make: *** [Makefile:746: build] Error 2
At this point, i have to say, that i have no experience with gcc on Termux in combination with the makefile of Stockfish. I never tried that seriously. The clang compiler on Termux for example works out of the box with the makefile of Stockfish, but the executable only runs in Termux environment (in console mode), not outside (DroidFish).

Seems with gcc the makefile tries to compile for armeabi-v7a based CPUs. Is that your intention? Despite that, the gcc part for Android is incorrect, need to be fixed.
Archimedes

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

Re: Termux (Linux environment for Android)

Post by Archimedes »

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.
Archimedes

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

Re: Termux (Linux environment for Android)

Post by Archimedes »

A short description, how Stockfish can be compiled with gcc on Termux can be found here: http://outskirts.altervista.org/forum/viewtopic.php?f=40&t=2685.
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 8 Hours, 33 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Termux (Linux environment for Android)

Post by kramnik »

In January I made a complete video-tutorial on how to compile Stockfish on Android, now I had the time to upload it on YouTube:

[bbvideo]https://www.youtube.com/watch?v=JjrDbNkYcpw[/bbvideo]

I hope you'll find it useful. beers
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 8 Hours, 33 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Termux (Linux environment for Android)

Post by kramnik »

I am traveling on train. I was bored so I wrote this simple program with Termux to obtain the square root of any number:

https://we.tl/t-rvl8NMy5YF

Could someone having any kind of Linux if it works in that environment please?
Post Reply

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