Compiling Stockfish with gcc on Termux

Moderators: Elijah, Igbo, timetraveller

MichaelM
I've been banned!
Points: 17 852,00 
Posts: 234
Joined: 27/08/2020, 23:44
Status: Offline (Active 8 Months, 3 Weeks, 3 Days, 14 Hours, 50 Minutes ago)
Topics: 3
Reputation: 255
1
Has thanked: 389 times
Been thanked: 362 times

Re: Compiling Stockfish with gcc on Termux

Post by MichaelM »

kramnik wrote: 06/11/2021, 12:36 I was able to compile BrainLearn on Termux using clang and it worked until it was in that environment, but as soon as I exported it outside Termux and in the Droidfish uci folder it stopped to work... Any idea?
Look into Leon's thread:
http://outskirts.altervista.org/forum/viewtopic.php?f=40&p=21364#p21364

About here is the important part:
_______________
If it's give you fatal error (like it most of time it's gives me)header missing like <fstream> , <istream>
its because std ib++ is not loaded in main memory, you have to first build using "clang" and built-in cross compiler "aarch64-linux-android-clang++" after that remove that build (because its useless without ndk) and run again the NDK build command. This just my theory I am not 100% sure why it's actually happened but my trick works.
_______________

But I never had this problem in Droidfish since in my Droidfish
std lib++ is installed and everything compiled in Termux always also worked in Droidfish. Maybe you have to wait for Archimedes, he knows what to do smile3
kramnik

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

Re: Compiling Stockfish with gcc on Termux

Post by kramnik »

"std lib++" is not a package anywhere, please provide the exact correct name of the package to install.
MichaelM wrote: 06/11/2021, 13:08
kramnik wrote: 06/11/2021, 12:36 I was able to compile BrainLearn on Termux using clang and it worked until it was in that environment, but as soon as I exported it outside Termux and in the Droidfish uci folder it stopped to work... Any idea?
Look into Leon's thread:
http://outskirts.altervista.org/forum/viewtopic.php?f=40&p=21364#p21364

About here is the important part:
_______________
If it's give you fatal error (like it most of time it's gives me)header missing like <fstream> , <istream>
its because std ib++ is not loaded in main memory, you have to first build using "clang" and built-in cross compiler "aarch64-linux-android-clang++" after that remove that build (because its useless without ndk) and run again the NDK build command. This just my theory I am not 100% sure why it's actually happened but my trick works.
_______________

But I never had this problem in Droidfish since in my Droidfish
std lib++ is installed and everything compiled in Termux always also worked in Droidfish. Maybe you have to wait for Archimedes, he knows what to do smile3
MichaelM
I've been banned!
Points: 17 852,00 
Posts: 234
Joined: 27/08/2020, 23:44
Status: Offline (Active 8 Months, 3 Weeks, 3 Days, 14 Hours, 50 Minutes ago)
Topics: 3
Reputation: 255
1
Has thanked: 389 times
Been thanked: 362 times

Re: Compiling Stockfish with gcc on Termux

Post by MichaelM »

kramnik wrote: 06/11/2021, 13:41 "std lib++" is not a package anywhere, please provide the exact correct name of the package to install.
MichaelM wrote: 06/11/2021, 13:08
kramnik wrote: 06/11/2021, 12:36 I was able to compile BrainLearn on Termux using clang and it worked until it was in that environment, but as soon as I exported it outside Termux and in the Droidfish uci folder it stopped to work... Any idea?
Look into Leon's thread:
http://outskirts.altervista.org/forum/viewtopic.php?f=40&p=21364#p21364

About here is the important part:
_______________
If it's give you fatal error (like it most of time it's gives me)header missing like <fstream> , <istream>
its because std ib++ is not loaded in main memory, you have to first build using "clang" and built-in cross compiler "aarch64-linux-android-clang++" after that remove that build (because its useless without ndk) and run again the NDK build command. This just my theory I am not 100% sure why it's actually happened but my trick works.
_______________

But I never had this problem in Droidfish since in my Droidfish
std lib++ is installed and everything compiled in Termux always also worked in Droidfish. Maybe you have to wait for Archimedes, he knows what to do smile3
We have to wait for Archimedes! I have just before realized that my builds work fine in Droidfish on two devices BUT do not work on two others. And on one of the working one, an old armv7, Termux nor any package is installed.
Archimedes

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

Re: Compiling Stockfish with gcc on Termux

Post by Archimedes »

kramnik wrote: 06/11/2021, 12:36 I was able to compile BrainLearn on Termux using clang and it worked until it was in that environment, but as soon as I exported it outside Termux and in the Droidfish uci folder it stopped to work... Any idea?
Add -static-libstdc++ to one of your LDFLAGS for clang and also make sure, you have installed ndk-multilib.

Example:

Code: Select all

ifeq ($(arch),$(filter $(arch),armv7 armv8))
	ifeq ($(OS),Android)
		CXXFLAGS += -m$(bits)
		LDFLAGS += -m$(bits) -static-libstdc++
kramnik

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

Re: Compiling Stockfish with gcc on Termux

Post by kramnik »

Just tried with make profile-build ARCH=armv8 COMP=clang, it doesn't work outside Termux.
Archimedes wrote: 06/11/2021, 14:22
kramnik wrote: 06/11/2021, 12:36 I was able to compile BrainLearn on Termux using clang and it worked until it was in that environment, but as soon as I exported it outside Termux and in the Droidfish uci folder it stopped to work... Any idea?
Add -static-libstdc++ to one of your LDFLAGS for clang and also make sure, you have installed ndk-multilib.

Example:

Code: Select all

ifeq ($(arch),$(filter $(arch),armv7 armv8))
	ifeq ($(OS),Android)
		CXXFLAGS += -m$(bits)
		LDFLAGS += -m$(bits) -static-libstdc++
MichaelM
I've been banned!
Points: 17 852,00 
Posts: 234
Joined: 27/08/2020, 23:44
Status: Offline (Active 8 Months, 3 Weeks, 3 Days, 14 Hours, 50 Minutes ago)
Topics: 3
Reputation: 255
1
Has thanked: 389 times
Been thanked: 362 times

Re: Compiling Stockfish with gcc on Termux

Post by MichaelM »

kramnik wrote: 06/11/2021, 17:52 Just tried with make profile-build ARCH=armv8 COMP=clang, it doesn't work outside Termux.
Archimedes wrote: 06/11/2021, 14:22
kramnik wrote: 06/11/2021, 12:36 I was able to compile BrainLearn on Termux using clang and it worked until it was in that environment, but as soon as I exported it outside Termux and in the Droidfish uci folder it stopped to work... Any idea?
Add -static-libstdc++ to one of your LDFLAGS for clang and also make sure, you have installed ndk-multilib.

Example:

Code: Select all

ifeq ($(arch),$(filter $(arch),armv7 armv8))
	ifeq ($(OS),Android)
		CXXFLAGS += -m$(bits)
		LDFLAGS += -m$(bits) -static-libstdc++
For me now on all four tested devices my own compiles work fine in DroidFish. It seems you have some other problems.
kramnik

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

Re: Compiling Stockfish with gcc on Termux

Post by kramnik »

Are you using the parameter profile-build?
MichaelM wrote: 06/11/2021, 18:50
kramnik wrote: 06/11/2021, 17:52 Just tried with make profile-build ARCH=armv8 COMP=clang, it doesn't work outside Termux.
Archimedes wrote: 06/11/2021, 14:22
Add -static-libstdc++ to one of your LDFLAGS for clang and also make sure, you have installed ndk-multilib.

Example:

Code: Select all

ifeq ($(arch),$(filter $(arch),armv7 armv8))
	ifeq ($(OS),Android)
		CXXFLAGS += -m$(bits)
		LDFLAGS += -m$(bits) -static-libstdc++
For me now on all four tested devices my own compiles work fine in DroidFish. It seems you have some other problems.
MichaelM
I've been banned!
Points: 17 852,00 
Posts: 234
Joined: 27/08/2020, 23:44
Status: Offline (Active 8 Months, 3 Weeks, 3 Days, 14 Hours, 50 Minutes ago)
Topics: 3
Reputation: 255
1
Has thanked: 389 times
Been thanked: 362 times

Re: Compiling Stockfish with gcc on Termux

Post by MichaelM »

kramnik wrote: 06/11/2021, 19:02 Are you using the parameter profile-build?
Yes, just compiled and tested in Droidfish.
Compiler output and command-line:
...
clang++ -o stockfish benchmark.o bitbase.o bitboard.o endgame.o evaluate.o learn.o main.o material.o misc.o montecarlo.o movegen.o movepick.o pawns.o polybook.o position.o psqt.o search.o thread.o timeman.o tt.o uci.o ucioption.o tune.o tbprobe.o evaluate_nnue.o half_ka_v2_hm.o -lcurl -fprofile-use -latomic -m64 -static-libstdc++ -Wall -Wcast-qual -fexceptions -std=c++17 -DNNUE_EMBEDDING_OFF -fprofile-instr-use=stockfish.profdata -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -fexperimental-new-pass-manager -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -flto -fPIE -fPIE -pie
make[2]: Leaving directory '/data/data/com.termux/files/home/cecsa28/src/BrainLearn/src'
make[1]: Leaving directory '/data/data/com.termux/files/home/cecsa28/src/BrainLearn/src'

Step 4/4. Deleting profile data ...
make ARCH=armv8 COMP=clang profileclean
make[1]: Entering directory '/data/data/com.termux/files/home/cecsa28/src/BrainLearn/src'
make[1]: Leaving directory '/data/data/com.termux/files/home/cecsa28/src/BrainLearn/src'
~/.../BrainLearn/src $ make -j 6 profile-build ARCH=armv8 COMP=clang

I have used the cecsa script one time some days ago and did later compilations by the command line above. :smile2:
Archimedes

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

Re: Compiling Stockfish with gcc on Termux

Post by Archimedes »

kramnik wrote: 06/11/2021, 17:52 Just tried with make profile-build ARCH=armv8 COMP=clang, it doesn't work outside Termux.
Archimedes wrote: 06/11/2021, 14:22
kramnik wrote: 06/11/2021, 12:36 I was able to compile BrainLearn on Termux using clang and it worked until it was in that environment, but as soon as I exported it outside Termux and in the Droidfish uci folder it stopped to work... Any idea?
Add -static-libstdc++ to one of your LDFLAGS for clang and also make sure, you have installed ndk-multilib.

Example:

Code: Select all

ifeq ($(arch),$(filter $(arch),armv7 armv8))
	ifeq ($(OS),Android)
		CXXFLAGS += -m$(bits)
		LDFLAGS += -m$(bits) -static-libstdc++
Just see, we talk about the BrainLearn engine. Here we have another issue. This time with the curl library which is not embedded in the executable. Same with ShashChess it works on many devices (where the curl library is on board) but not on all (on some devices the curl library seems not to be present or up to date). I see no other reason. I bet, we need a static version of the curl library. This version will work on almost all devices.

When your own compiles not work for you, i bet, my compiles also don't work for you. Need to be tested.
kramnik

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

Re: Compiling Stockfish with gcc on Termux

Post by kramnik »

I've tried to reinstall everything, Termux included, but it keeps to not work. Where is your version I wanna test it.
Archimedes wrote: 07/11/2021, 9:53
kramnik wrote: 06/11/2021, 17:52 Just tried with make profile-build ARCH=armv8 COMP=clang, it doesn't work outside Termux.
Archimedes wrote: 06/11/2021, 14:22
Add -static-libstdc++ to one of your LDFLAGS for clang and also make sure, you have installed ndk-multilib.

Example:

Code: Select all

ifeq ($(arch),$(filter $(arch),armv7 armv8))
	ifeq ($(OS),Android)
		CXXFLAGS += -m$(bits)
		LDFLAGS += -m$(bits) -static-libstdc++
Just see, we talk about the BrainLearn engine. Here we have another issue. This time with the curl library which is not embedded in the executable. Same with ShashChess it works on many devices (where the curl library is on board) but not on all (on some devices the curl library seems not to be present or up to date). I see no other reason. I bet, we need a static version of the curl library. This version will work on almost all devices.

When your own compiles not work for you, i bet, my compiles also don't work for you. Need to be tested.
MichaelM
I've been banned!
Points: 17 852,00 
Posts: 234
Joined: 27/08/2020, 23:44
Status: Offline (Active 8 Months, 3 Weeks, 3 Days, 14 Hours, 50 Minutes ago)
Topics: 3
Reputation: 255
1
Has thanked: 389 times
Been thanked: 362 times

Re: Compiling Stockfish with gcc on Termux

Post by MichaelM »

kramnik wrote: 07/11/2021, 13:03 I've tried to reinstall everything, Termux included, but it keeps to not work. Where is your version I wanna test it.
Man, for example here:

https://app.box.com/s/dlxclf0l8dh1gisodpdrnmrtumqi5sjb

Edit: And one or two more of Archimedes compiles :sm36:
kramnik

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

Re: Compiling Stockfish with gcc on Termux

Post by kramnik »

Whoa, this one is neither standalone... (Standard) Droidfish doesn't even recognize it...
MichaelM wrote: 07/11/2021, 13:08
kramnik wrote: 07/11/2021, 13:03 I've tried to reinstall everything, Termux included, but it keeps to not work. Where is your version I wanna test it.
Man, for example here:

https://app.box.com/s/dlxclf0l8dh1gisodpdrnmrtumqi5sjb

Edit: And one or two more of Archimedes compiles :sm36:
Archimedes

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

Re: Compiling Stockfish with gcc on Termux

Post by Archimedes »

kramnik wrote: 07/11/2021, 13:12 Whoa, this one is neither standalone... (Standard) Droidfish doesn't even recognize it...
I have the same problem with Clang on Termux and Android NDK on Termux. I could compile BrainLearn and ShashChess (with the live book feature), but the executables do not run on all devices. On my devices they runs. Formerly, i removed the live book feature when i did a compile with Android NDK (on Windows). There was never a problem with it. The problems occurs with the non removed live book feature. Therefore the reason for the compatibility issues must be the libcurl library. It has to be included statically in the exutables.
kramnik

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

Re: Compiling Stockfish with gcc on Termux

Post by kramnik »

Yes, I've already noticed that rmeoving the livebook (and learning) it worked. But in that case it wouldn't be BrainLearn anymore.

I wish to know how to statically include that library...

At this point I can't see other ways than compiling the engines into apk packages, provides that the installer works like in Windows: installing both executable and libraries.
Archimedes wrote: 07/11/2021, 13:30
kramnik wrote: 07/11/2021, 13:12 Whoa, this one is neither standalone... (Standard) Droidfish doesn't even recognize it...
I have the same problem with Clang on Termux and Android NDK on Termux. I could compile BrainLearn and ShashChess (with the live book feature), but the executables do not run on all devices. On my devices they runs. Formerly, i removed the live book feature when i did a compile with Android NDK (on Windows). There was never a problem with it. The problems occurs with the non removed live book feature. Therefore the reason for the compatibility issues must be the libcurl library. It has to be included statically in the exutables.
MichaelM
I've been banned!
Points: 17 852,00 
Posts: 234
Joined: 27/08/2020, 23:44
Status: Offline (Active 8 Months, 3 Weeks, 3 Days, 14 Hours, 50 Minutes ago)
Topics: 3
Reputation: 255
1
Has thanked: 389 times
Been thanked: 362 times

Re: Compiling Stockfish with gcc on Termux

Post by MichaelM »

kramnik wrote: 07/11/2021, 13:37 Yes, I've already noticed that rmeoving the livebook (and learning) it worked. But in that case it wouldn't be BrainLearn anymore.

I wish to know how to statically include that library...

At this point I can't see other ways than compiling the engines into apk packages, provides that the installer works like in Windows: installing both executable and libraries.
You can look into the engine apks from Leon (apks are just zips). No libs are installed. Thus, creating apks is not a solution for your problem. Missing libs have to be statically binded/linked into the exe.
Edit: http://outskirts.altervista.org/forum/viewtopic.php?f=40&t=1895
Post Reply

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