Compiling Stockfish with gcc on Termux

Moderators: Elijah, Igbo, timetraveller

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, 33 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling Stockfish with gcc on Termux

Post by Archimedes »

hagtorp wrote: 03/10/2022, 17:13 Hi there, long time no see. Does anyone have CCTools packages? The site from where it all swayed does not work, but I do not have a backup.
https://web.archive.org/web/20211227192213/https://cctools.info/index.php/Main_Page
LittleJoe

Top contribute Forum Engines Maker
Forum Contributions
Points: 14 078,00 
Posts: 327
Joined: 17/10/2020, 22:28
Status: Offline (Active 5 Days, 8 Hours, 36 Minutes ago)
Medals: 2
Topics: 5
Reputation: 506
Has thanked: 349 times
Been thanked: 671 times

Re: Compiling Stockfish with gcc on Termux

Post by LittleJoe »

Archimedes wrote: 04/10/2022, 9:44
hagtorp wrote: 03/10/2022, 17:13 Hi there, long time no see. Does anyone have CCTools packages? The site from where it all swayed does not work, but I do not have a backup.
https://web.archive.org/web/20211227192213/https://cctools.info/index.php/Main_Page
Did anyone test it if everything necessary was archived and allows a fresh installation of the cctools/gcc?
Would be nice to know since all termux users will buy a new phone or tablet sooner or later.
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, 33 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling Stockfish with gcc on Termux

Post by Archimedes »

The directories still exist. So everything should still work.

https://cctools.info/dists/termux/
LittleJoe

Top contribute Forum Engines Maker
Forum Contributions
Points: 14 078,00 
Posts: 327
Joined: 17/10/2020, 22:28
Status: Offline (Active 5 Days, 8 Hours, 36 Minutes ago)
Medals: 2
Topics: 5
Reputation: 506
Has thanked: 349 times
Been thanked: 671 times

Re: Compiling Stockfish with gcc on Termux

Post by LittleJoe »

hagtorp wrote: 03/10/2022, 17:13
@hagtorp since you probably will install cctools, let us know, if it worked.
hagtorp
Forum Contributions
Points: 19 796,00 
Posts: 159
Joined: 04/11/2019, 3:15
Status: Offline (Active 7 Months, 1 Day, 2 Hours, 15 Minutes ago)
Topics: 3
Reputation: 30
Has thanked: 9 times
Been thanked: 24 times

Re: Compiling Stockfish with gcc on Termux

Post by hagtorp »

LittleJoe wrote: 04/10/2022, 12:32
@hagtorp since you probably will install cctools, let us know, if it worked.
[/quote]

Maybe with time. So far I am satisfied with the standard gcc-11 :sm36:
hagtorp
Forum Contributions
Points: 19 796,00 
Posts: 159
Joined: 04/11/2019, 3:15
Status: Offline (Active 7 Months, 1 Day, 2 Hours, 15 Minutes ago)
Topics: 3
Reputation: 30
Has thanked: 9 times
Been thanked: 24 times

Re: Compiling Stockfish with gcc on Termux

Post by hagtorp »

in general, you can build gcc yourself in termux. I collected :sm165:
LittleJoe

Top contribute Forum Engines Maker
Forum Contributions
Points: 14 078,00 
Posts: 327
Joined: 17/10/2020, 22:28
Status: Offline (Active 5 Days, 8 Hours, 36 Minutes ago)
Medals: 2
Topics: 5
Reputation: 506
Has thanked: 349 times
Been thanked: 671 times

Re: Compiling Stockfish with gcc on Termux

Post by LittleJoe »

hagtorp wrote: 04/10/2022, 13:14
LittleJoe wrote: 04/10/2022, 12:32
@hagtorp since you probably will install cctools, let us know, if it worked.

Maybe with time. So far I am satisfied with the standard gcc-11 :sm36:
Where did you get gcc11 for termux? I also would like to have it! smile218
Edit: OK, you compiled it by yourself, great!
Could you please make a package (or a somewhat detailed description how to do it) for the ones who are to stupid for self-compiling gcc11 like me?
hagtorp
Forum Contributions
Points: 19 796,00 
Posts: 159
Joined: 04/11/2019, 3:15
Status: Offline (Active 7 Months, 1 Day, 2 Hours, 15 Minutes ago)
Topics: 3
Reputation: 30
Has thanked: 9 times
Been thanked: 24 times

Re: Compiling Stockfish with gcc on Termux

Post by hagtorp »

[/quote]

Where did you get gcc11 for termux? I also would like to have it! smile218
Edit: OK, you compiled it by yourself, great!
Could you please make a package for the ones who are to stupid for self-compiling gcc11 like me?
[/quote]

No, right now I'm using gcc-11 which comes with termux and it works well. I say that I used to build compilers myself.
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, 33 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling Stockfish with gcc on Termux

Post by Archimedes »

Another way to use GCC under Termux is to use a distribution under Termux (e.g. Arch Linux) and use the GCC compiler inside of this distribution. Did a short test with Arch Linux and it worked so far. However, the compilation takes an extremely long time. Maybe there are better distributions for Termux out there.

https://wiki.termux.com/wiki/PRoot
hagtorp
Forum Contributions
Points: 19 796,00 
Posts: 159
Joined: 04/11/2019, 3:15
Status: Offline (Active 7 Months, 1 Day, 2 Hours, 15 Minutes ago)
Topics: 3
Reputation: 30
Has thanked: 9 times
Been thanked: 24 times

Re: Compiling Stockfish with gcc on Termux

Post by hagtorp »

Archimedes wrote: 05/10/2022, 13:23 Another way to use GCC under Termux is to use a distribution under Termux (e.g. Arch Linux) and use the GCC compiler inside of this distribution. Did a short test with Arch Linux and it worked so far. However, the compilation takes an extremely long time. Maybe there are better distributions for Termux out there.

https://wiki.termux.com/wiki/PRoot
What for? There is also gcc-11.1 from its-pointless. It works well 👌 and is faster than clang
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 5 Days, 23 Hours, 11 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 »

This method is still great. ssfgmfgsoke

That was the one I mentioned few weeks ago Archimedes. Glad I've found it back.
Archimedes wrote: 17/10/2021, 13:06 Make changes to the makefile, as the following code pieces are shown:

Before:

Code: Select all

ifeq ($(COMP),gcc)
	comp=gcc
	CXX=g++
	CXXFLAGS += -pedantic -Wextra -Wshadow

	ifeq ($(arch),$(filter $(arch),armv7 armv8))
		ifeq ($(OS),Android)
			CXXFLAGS += -m$(bits)
			LDFLAGS += -m$(bits)
After:

Code: Select all

ifeq ($(COMP),gcc)
	comp=gcc
	CXX=g++
	CXXFLAGS += -pedantic -Wextra -Wshadow

	ifeq ($(arch),$(filter $(arch),armv7 armv8))
		ifeq ($(OS),Android)
			CXXFLAGS += 
			LDFLAGS += 
Before:

Code: Select all

### Sometimes gcc is really clang
ifeq ($(COMP),gcc)
After:

Code: Select all

### Sometimes gcc is really clang
ifeq ($(COMP),)
Before:

Code: Select all

### 3.3 Optimization
ifeq ($(optimize),yes)

	CXXFLAGS += -O3

	ifeq ($(comp),gcc)
		ifeq ($(OS), Android)
			CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
After:

Code: Select all

### 3.3 Optimization
ifeq ($(optimize),yes)

	CXXFLAGS += -O3

	ifeq ($(comp),gcc)
		ifeq ($(OS), Android)
			CXXFLAGS += -march=native
Now you can compile Stockfish with gcc and PGO optimization with the following command:

Code: Select all

make -j profile-build ARCH=armv8 COMP=gcc
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, 33 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling Stockfish with gcc on Termux

Post by Archimedes »

kramnik wrote: 25/03/2023, 5:20 This method is still great. ssfgmfgsoke

That was the one I mentioned few weeks ago Archimedes. Glad I've found it back.
Archimedes wrote: 17/10/2021, 13:06 Make changes to the makefile, as the following code pieces are shown:

Before:

Code: Select all

ifeq ($(COMP),gcc)
	comp=gcc
	CXX=g++
	CXXFLAGS += -pedantic -Wextra -Wshadow

	ifeq ($(arch),$(filter $(arch),armv7 armv8))
		ifeq ($(OS),Android)
			CXXFLAGS += -m$(bits)
			LDFLAGS += -m$(bits)
After:

Code: Select all

ifeq ($(COMP),gcc)
	comp=gcc
	CXX=g++
	CXXFLAGS += -pedantic -Wextra -Wshadow

	ifeq ($(arch),$(filter $(arch),armv7 armv8))
		ifeq ($(OS),Android)
			CXXFLAGS += 
			LDFLAGS += 
Before:

Code: Select all

### Sometimes gcc is really clang
ifeq ($(COMP),gcc)
After:

Code: Select all

### Sometimes gcc is really clang
ifeq ($(COMP),)
Before:

Code: Select all

### 3.3 Optimization
ifeq ($(optimize),yes)

	CXXFLAGS += -O3

	ifeq ($(comp),gcc)
		ifeq ($(OS), Android)
			CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
After:

Code: Select all

### 3.3 Optimization
ifeq ($(optimize),yes)

	CXXFLAGS += -O3

	ifeq ($(comp),gcc)
		ifeq ($(OS), Android)
			CXXFLAGS += -march=native
Now you can compile Stockfish with gcc and PGO optimization with the following command:

Code: Select all

make -j profile-build ARCH=armv8 COMP=gcc
This is just a quick and messy solution. I'm glad it still works. But in the meantime I use my own Makefile for this. This way I am mostly independent against changes in the original Makefile. However, the Makefile is only for arm64-v8a and the network is not automatically downloaded. Just copy the Makefile into the src directory of Stockfish and enter the following two commands. GCC is the default compiler.

Code: Select all

make net
make profile-build
The Makefile is located in the CECSA script under /etc/Stockfish.
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 5 Days, 23 Hours, 11 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'm getting the following error while trying to compile BrainLearn:

Code: Select all

In file included from position.h:31,
                 from endgame.h:28,
                 from material.h:22,
                 from material.cpp:22:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
g++  -Wall -Wcast-qual -fexceptions -std=c++17 -fprofile-generate=profdir -pedantic -Wextra -Wshadow -Wmissing-declarations -DUSE_PTHREADS -DNDEBUG -O3 -march=native -DIS_64BIT -DUSE_POPCNT -DUSE_NEON=8 -flto -flto-partition=one -fPIE   -c -o ucioption.o ucioption.cpp
In file included from position.h:31,
                 from benchmark.cpp:26:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
In file included from position.h:31,
                 from endgame.h:28,
                 from endgame.cpp:22:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
In file included from position.h:31,
                 from endgame.h:28,
                 from material.h:22,
                 from evaluate.cpp:32:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [<builtin>: benchmark.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [<builtin>: endgame.o] Error 1
make[2]: *** [<builtin>: evaluate.o] Error 1
make[2]: *** [<builtin>: material.o] Error 1
In file included from learn.cpp:4:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [<builtin>: learn.o] Error 1
In file included from position.h:31,
                 from polybook.h:23,
                 from search.cpp:26:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [<builtin>: search.o] Error 1
In file included from position.h:31,
                 from endgame.h:28,
                 from main.cpp:22:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
In file included from bitboard.cpp:23:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [<builtin>: main.o] Error 1
make[2]: *** [<builtin>: bitboard.o] Error 1
In file included from position.h:31,
                 from movepick.h:27,
                 from movepick.cpp:22:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
In file included from pawns.h:22,
                 from pawns.cpp:23:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [<builtin>: pawns.o] Error 1
make[2]: *** [<builtin>: movepick.o] Error 1
In file included from search.h:24,
                 from thread.cpp:23:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [<builtin>: thread.o] Error 1
In file included from position.h:31,
                 from polybook.h:23,
                 from polybook.cpp:19:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
In file included from position.h:31,
                 from movegen.cpp:22:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
In file included from ucioption.cpp:25:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [<builtin>: polybook.o] Error 1
make[2]: *** [<builtin>: ucioption.o] Error 1
In file included from position.cpp:28:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [<builtin>: movegen.o] Error 1
make[2]: *** [<builtin>: position.o] Error 1
In file included from misc.cpp:67:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [<builtin>: misc.o] Error 1
In file included from tt.cpp:24:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [<builtin>: tt.o] Error 1
In file included from position.h:31,
                 from uci.cpp:28:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
In file included from search.h:24,
                 from timeman.cpp:23:
misc.h:32:10: fatal error: mm_malloc.h: No such file or directory
   32 | #include <mm_malloc.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [<builtin>: uci.o] Error 1
make[2]: *** [<builtin>: timeman.o] Error 1
make[2]: Leaving directory '/data/data/com.termux/files/home/BrainLearn-23/BrainLearn-23/src'
make[1]: *** [Makefile:1022: gcc-profile-make] Error 2
make[1]: Leaving directory '/data/data/com.termux/files/home/BrainLearn-23/BrainLearn-23/src'
make: *** [Makefile:859: profile-build] Error 2
I searched on Google about "mm_malloc.h: No such file or directory" but I didn't found anything relevant. Looks like this header is inside the libgcc-*-dev that is not in the Termux repositories.

Any help?
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, 33 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling Stockfish with gcc on Termux

Post by Archimedes »

kramnik wrote: 10/04/2023, 11:37 I searched on Google about "mm_malloc.h: No such file or directory" but I didn't found anything relevant. Looks like this header is inside the libgcc-*-dev that is not in the Termux repositories.
Should be present in the include directory of the Clang compiler.
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 5 Days, 23 Hours, 11 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 »

So how can I use it to compile BrainLearn?
Archimedes wrote: 14/04/2023, 9:54
kramnik wrote: 10/04/2023, 11:37 I searched on Google about "mm_malloc.h: No such file or directory" but I didn't found anything relevant. Looks like this header is inside the libgcc-*-dev that is not in the Termux repositories.
Should be present in the include directory of the Clang compiler.
Post Reply

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