top of page
Writer's pictureDarius

How to compile chess engines and programs for Linux ?


This article was inspired by MartinPL1977. Thank you :)


Your Linux and favorite distribution. You have perfected it down to the smallest detail. It looks beautiful, it is functional, the programs do their job. The whole system for you works better than any Windows or macOS machine.


You are proud of it and would like to be able to use modern engines and useful chess software. But... not everything you are interested in is ready to work immediately. It has to be compiled.


Is it difficult ?

Does it require specialized knowledge ?

How to do that ?


I will try to answer the questions posed above.


This article is for those who understand how Linux works and know what commands typed at the Linux command line do.


First I have some good informations for you. Compiling engines and programs in most cases is not difficult and comes down to typing just a few commands in the command line.


Typically, properly and independently compiled chess engines run slightly faster on the same computer on Linux than the same engines on a Windows computer.

Why is this the case ?

The easiest way to understand this is to use the example of buying a suit. When you buy - even in the best store - a suit, you choose a particular size. The suit fits and it's fine.


On the other hand, when you go to a tailor, who will tailor the suit to your exact measurements, you will not only get a suit that fits, but one that is exactly tailored to your measurements. And this tailor-made suit will fit you perfectly.


Without going into technical details - it is similar with compilation of chess software, which due to its specialized nature - works best on the machine on which it was compiled. It is not a coincidence that at important competitions where chess engines have participated and are participating, they are run on Linux - in the environment where they were previously compiled.


How much difference in speed can there be between an engine compiled for a particular machine versus the same engine not optimized for that machine ?

The difference can range from a fraction of a percent to several percent.


Is it much or is it little ? It depends.

During usual chess engine activities, such as chess game analysis or training applications - it does not matter much.

But if the engine participates in competitions or it is important to get as much power as possible or you use it to analyze difficult positions in correspondence games or looking for an effective novelty in a chess opening - then the speed higher by "just" a fraction of a percent will be important, it may increase the chance of a draw or even victory in an important chess game.


You don't need specialized knowledge to compile a chess engine or program properly. You don't even need to know how to program. However, it is worth reading with concentration and understanding, because usually in the sources of the program there is a file describing the steps of compilation of the given engine or chess program.



Ok. So without further ado, what are we going to compile ?


First, we'll take a compilation of two free modern and powerful chess engines, Berserk and Stockfish. Then we will take a compilation of the best free chess database program Scid vs PC.



What do you need to compile ?


1. Linux Distribution.

It doesn't really matter what distribution it is. It will compile the same way on Arch, Debian, Fedora, Gentoo, Ubuntu or any other distribution. It doesn't really matter if the Linux distribution you are using uses an AMD, ARM or other processor.


2. Compiler.

We will compile software written in C / C++ so we need a compiler called GCC (GNU Compiler Collection).


3. Source code.

It takes source code in file/s form for the GCC compiler to be able to create a working engine / program.


4. Anything else ?

In some cases, depending on, for example, the installed version of the GCC compiler and the Linux distribution libraries, you may need to install components specified by the compiler.


5. Time. How long does it take to compile ?

On a modern computer, it usually takes tens of seconds to compile.

Even on older computers, e.g. 10-15 years old, compiling a chess engine will take from tens of seconds to several minutes. The compilation of a program like Scid vs. PC may take a little longer because of its larger size.



Will the compilation be described in detail ?


All compilations will be explained and presented in such a way that the Reader, by following all compilation steps - will be able to compile the software described below by himself.

Due to the nature of the compilation process and the required knowledge of the Reader, the compilation descriptions will not address detailed issues of how Linux works and the effects of executing command line commands.



Workshops for compilation.


I am using Debian GNU/Linux 10 (buster).

This distribution is supported until 2024 (LTS - Long Term Support); it is a very stable and high quality distribution with frequent updates.

Debian runs on my computer with ARM64 processors.


The compilation will be performed by GCC version 8.3.0.


If you do not have the GCC compiler installed, I would refer you to the help system of the Linux distribution you are using. There you will get information how to install GCC.


In Debian, the following steps are required to install GCC:


1. Update the packages list:

sudo apt update

2. Install the build-essential package by running:

sudo apt install build-essential

3. You can skip this step.

You would like also to install the manual pages that includes documentation about using GNU/Linux for (among others) compiling.

sudo apt-get install manpages-dev

4. To confirm that the GCC compiler is successfully installed type:

gcc --version


A compilation of the Berserk chess engine.


Berserk is licensed under the GPL v3.0.


We will be compiling the latest publicly available version of this engine.

The Berserk source code is available on GitHub at: https://github.com/jhonnold/berserk


To compile Berserk we will use the information on this engine's page.


1.

In the first step, we will select the directory where the source code will reside.


Type:

cd

Of course, you must press the Enter key after typing each command.


2.

In this, step we will download the source code.


Type the command:



If the download does not start, it is likely that git is not installed on your system - then install git and repeat step #2.



How to install git
sudo apt install git


On my internet connection, the download took about 30 seconds.


3.

Type:

cd berserk/src


4.

Type the command:

make basic

Now the compilation will take place.

If any errors occur during compilation, the engine will not compile and the GCC compiler will show messages on the screen.


Unfortunately, the compilation failed.

Why? Look carefully at the messages the compiler gave you.

GCC suggests that the stdlib.h library should be added to the nn.c file.


Open the nn.c file in any text file editor - I used the system Text Editor.


In line number 20, type:

#include <stdlib.h>

Save the file and then close it.


Go back to the command prompt and type again: make basic

make basic

Success!

Berserk chess engine has been compiled :)


So let's see if it works.

Type:

./berserk

And then type:

uci

Confirm with the Enter key.


Perfect !!

The latest Berserk 20220603 is ready to go :)


When you type:

quit

(Enter)


the engine will be switched off.


Below I share the source code and compiled Berserk 20220603.



A compilation of the Stockfish chess engine.


Stockfish is open source (GPLv3 license).

We will be compiling the latest publicly available version of this engine.


We start similarly to the previous case. We select a directory and download the source code.


1.

Type the command:


Good. The Stockfish engine source code has been downloaded.


2.

Type the command:

cd Stockfish/src


3.

Type the command:

make

Stockfish can be compiled on many different architectures. The make command will list all available architectures.


It is important to choose the correct architecture to which Stockfish should be compiled.

4.

For my architecture, the appropriate compile command is:

make -j build ARCH=armv8

or:

make -j profile-build ARCH=armv8 COMP=gcc

(Faster build with profile-guided optimization, thank you to user kramnik for pointing this out.)



After some time, the compilation is finished.


5.

One more step. Type:

make strip

and confirm with the Enter key.



Perfect!

The Stockfish chess engine is ready to go :)


Let's see if it works by typing:

./stockfish

And then type:

uci

Confirm with the Enter key.


Oh yes, Stockfish 090622 works!


When you type:

quit

(Enter)


The engine will be switched off.


Below I share the source code and compiled Stockfish 090622.



Scid vs. PC program compilation


Scid vs. PC is free software licensed under the GNU General Public License version 2.0 (GPLv2).


Scid vs. PC is a program not inferior in functionality to professional database programs such as Chess Assistant and ChessBase.

With two previously compiled chess engines available (Berserk & Stockfish), it would be nice to use them with good software.


If you want to learn how to use this program in various purposes, I invite you, dear reader, to the course area: Scid vs. PC - Efficient work with a chess database

If you decide before compilation that you want to use the already compiled Scid vs. PC prepared for installation in a .DEB package, you can download it from here: https://sourceforge.net/projects/scidvspc/files/linux%20packages/


It is worth noting that the Scid vs. PC developers state that:

"These are third party packages, not compiled by the ScidvsPC team."


So you download at your own risk.

Also, in the above pasted location, there is no .DEB package for the latest version of Scid vs. PC 4.23 ( as of 2022-06-09 ).


Ok, let's get started then!


1.

After selecting the directory where the compilation will take place, we download the Scid vs. PC source code from: http://scidvspc.sourceforge.net/


2.

After unpacking the source, go to the command line and type:

cd scid_vs_pc-4.23/


3.

In the next step, execute the command:

./configure

This is a very important step before compilation begins. There will be a check that all the necessary requirements are met for the compilation of this serious project to be done correctly.


4.

Great.

We have received important information.

a) My environment has the Tcl/TK package installed, which is crucial for proper Scid vs PC compilation.

If you don't have the Tcl/TK package, you obviously need to install it before compiling Scid vs. PC.


b) The configuration program did not find the Tcl and TK libraries. And that's bad news, because not knowing where those libraries are located the compiler will surely spit out runtime errors - which will result in compilation failure.


Why did this happen?

Be calm - it is not your fault.


In the Linux environment, which is very rich in distributions, different versions of packages and libraries, sometimes some of them are in other places, sometimes you have to manually make some adjustments. What are those ? Such as we made before compiling the Berserk chess engine.


To find out exactly what the problem is, always run the compilation, then GCC will give you detailed information about possible errors.

And these errors can be eliminated.


c)

The configuration program has created and saved a Makefile, which is necessary to complete the compilation.


5.

Ok, now knowing that the compilation fails, let's see what information GCC will give us.


Type the command:

make

(Enter)



As we expected, the compiler aborted after encountering an error.

How to interpret this error ? In the file pgnscid.cpp in line number 30 the compiler could not find tcl.h according to the file path specified there.


What should we do? Open the file pgnscid.cpp and correct the path.

In the image below, the appropriately corrected entry in line number 30.

After saving the file, close it.


Again, at the command prompt, type the command:

make

and confirm by pressing Enter.



Let's see what the compiler has passed on this time.

The good news is that the compiler no longer showed the same error as before, which means that the change made to the pgnscid.cpp file was done correctly.


The next information is that a similar error occurred again - but in a different file.

What should I do? Make a correction in the same way.


For my environment, the same error occurred in across several files. I made the appropriate corrections and restarted the compilation by:

typing the make command.


This time the compilation was successful!

GCC did not find any errors :)


6.

Time to install Scid vs. PC.


Type the command:

sudo make install

(Enter)



Scid vs. PC and its components along with the default engines (Phalanx, Scidlet and Toga) will be placed in their respective locations.


7.

Is Scid vs. PC 4.23 ready to go ?


Let's check it by typing command:

scid

It's working !!


As of the date of writing this article, the latest Scid vs.PC 4.23 has been compiled and ready to go.

Below is the information and diagnostic data.


Below I share the source code that was used to compile Scid vs. PC 4.23.



 

Is this the end of this article ?


Let's install compiled Berserk and Stockfish engines in latest Scid vs. PC :)


This is how Berserk and Stockfish look like while working in Scid vs. PC 4.23.



There is one more thing...


Before I started writing this article, I wondered what engines and chess program to choose to show the work and flow of successful compilation.

I chose the Stockfish engine because it is so well written by its Community that its compilation is almost always bug-free, seamless, and possible on a wide variety of hardware and software architectures.


Of course, it is worth noting that the compilation environment is also important here.

If it is equipped with e.g. an appropriate compiler, libraries - then the chance for a successful compilation increases significantly.


I also chose Berserk from the chess engines, which on some architectures sometimes requires user intervention in the compilation process. I did this to show how to handle such a situation.


And at the end of this article I have chosen a program - Scid vs. PC 4.23, the compilation of which is not an easy task, although with a little determination you can achieve success. Big Success. Because we gain one of the best database programs in its class.



I would like to sincerely thank the Authors / Community of all the software described in this article. Without your knowledge and talent, such great software would certainly not be available.



 

Comentarios


bottom of page