compiling StockFish

Discussion of chess software programming and technical issues.

Moderators: hgm, chrisw, Rebel

lucasart
Posts: 3238
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

compiling StockFish

Post by lucasart »

Hello

I am trying to compile StockFish 1.9.1, but I get tons of errors.

I am running Linux (Ubuntu 10.10 64bit) and a recent version of g++ (4.4.5), and typing:

make profile-build ARCH=x86-64

Among the errors I get, g++ finds #include nested too deeply. For example position.h is including itself! And there's no #pragma once or #ifdef to stop the infinite self inclusion of the file, so the error seems logical to me...

I get the same errors if I just compile the simply way:

g++ -O3 -o ./sf *.cpp

Has anyone managed to compile it with gcc ?

Thank you
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: compiling StockFish

Post by mcostalba »

lucasart wrote:Hello

I am trying to compile StockFish 1.9.1, but I get tons of errors.

I am running Linux (Ubuntu 10.10 64bit) and a recent version of g++ (4.4.5), and typing:

make profile-build ARCH=x86-64

Among the errors I get, g++ finds #include nested too deeply. For example position.h is including itself! And there's no #pragma once or #ifdef to stop the infinite self inclusion of the file, so the error seems logical to me...

I get the same errors if I just compile the simply way:

g++ -O3 -o ./sf *.cpp

Has anyone managed to compile it with gcc ?

Thank you
Please post the full compile output, you know, I have lost my crystal ball ;-)

BTW try:

make build ARCH=x86-32
lucasart
Posts: 3238
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: compiling StockFish

Post by lucasart »

Actually I can't see it ending! But here are some extracts of it:

g++ -O3 -o ./sf *.cpp
(...)
from bitboard.h:30,
from application.cpp:25:
piece.h:25: error: #include nested too deeply
piece.h:27: error: #include nested too deeply
(...)
from history.h:30,
from movepick.h:29,
from position.h:36,
from movegen.h:28,
from position.h:35,
from endgame.h:28,
from application.cpp:27:
piece.h:25: error: #include nested too deeply

How do you compile it on Linux platforms ? I might just try the same and see if it works :)
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: compiling StockFish

Post by mcostalba »

lucasart wrote:Actually I can't see it ending!
What I need is the head of the error log, please post here the first 50 lines and compile with:

make build ARCH=x86-32
lucasart
Posts: 3238
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: compiling StockFish

Post by lucasart »

Sorry, my mistake. I must have modified accidentally modified the source before compiling. I re-downloaded a fresh copy of it and ran

make build ARCH=x86-32 > err.log

*** erro.log ***
make ARCH=x86-32 COMP=gcc config-sanity
make[1]: Entering directory `/home/lucas/Downloads/src'

Config:
debug: 'no'
optimize: 'yes'
arch: 'i386'
os: 'any'
bits: '32'
bigendian: 'no'
prefetch: 'yes'
bsfq: 'no'
popcnt: 'no'

Flags:
CXX: g++
CXXFLAGS: -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse
LDFLAGS: -lpthread

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

make[1]: Leaving directory `/home/lucas/Downloads/src'
make ARCH=x86-32 COMP=gcc all
make[1]: Entering directory `/home/lucas/Downloads/src'
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o application.o application.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o bitboard.o bitboard.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o pawns.o pawns.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o material.o material.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o endgame.o endgame.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o evaluate.o evaluate.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o main.o main.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o misc.o misc.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o move.o move.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o movegen.o movegen.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o history.o history.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o movepick.o movepick.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o search.o search.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o piece.o piece.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o position.o position.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o direction.o direction.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o tt.o tt.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o uci.o uci.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o ucioption.o ucioption.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o mersenne.o mersenne.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o book.o book.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o bitbase.o bitbase.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o san.o san.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o benchmark.o benchmark.cpp
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -c -o timeman.o timeman.cpp
g++ -o stockfish application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o misc.o move.o movegen.o history.o movepick.o search.o piece.o position.o direction.o tt.o uci.o ucioption.o mersenne.o book.o bitbase.o san.o benchmark.o timeman.o -lpthread
make[1]: Leaving directory `/home/lucas/Downloads/src'

*** end of err.log ***

so it seems good and displays no errors. However I can't find the output file ./stockfish.

So I thought I should try the normal way (I don't understand the make command) and did the same as what's in the err.log

g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -o ./sf *.cpp

But now I get the following problem:

/tmp/cclZS5J0.o: In function `init_threads':
/home/lucas/Downloads/src/search.cpp:2445: undefined reference to `pthread_create'

Finally I realized that compiling with

g++ -O3 -lpthread -o ./sf *.cpp

works like a charm !

Thank you again, and sorry for my silly questions. I'm not familiar with make, but I guess learning it is a necessary pain if you ever want to do portable code and compile it in an industrialised fashion.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: compiling StockFish

Post by mcostalba »

lucasart wrote:Sorry, my mistake. I must have modified accidentally modified the source before compiling. I re-downloaded a fresh copy of it and ran

make build ARCH=x86-32 > err.log
You have redirected stdout not stderr

Please try this:

make clean
make build ARCH=x86-32

It should work and you should find the stockfish bin, please report back if it doesn't, together with the full compile output.

BTW your 'manual' compile is not the supported way, you should compile with 'make'. Please type

make help

for a description of the available options.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: compiling StockFish

Post by Sven »

lucasart wrote:Actually I can't see it ending! But here are some extracts of it:

g++ -O3 -o ./sf *.cpp
(...)
from bitboard.h:30,
from application.cpp:25:
piece.h:25: error: #include nested too deeply
piece.h:27: error: #include nested too deeply
(...)
from history.h:30,
from movepick.h:29,
from position.h:36,
from movegen.h:28,
from position.h:35,
from endgame.h:28,
from application.cpp:27:
piece.h:25: error: #include nested too deeply

How do you compile it on Linux platforms ? I might just try the same and see if it works :)
In position.h of SF-1.9.1 downloaded a few minutes ago I cannot see any #include statements at lines 35 or 36, and piece.h does not have #include statements at lines 25 or 27. Also I checked all *.h files, they all have a correct protection against recursive inclusion with the usual #if !defined(XXX_H_INCLUDED) ... stuff. Are you sure you are looking at 100% SF-1.9.1 source code? If yes (which I would assume in the first place) then why would g++ print wrong line numbers, and mess up with the #if !defined(...) protection?

EDIT: Saw the recent replies too late, sorry. So it seems I found the same as you did already ...

Sven
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: compiling StockFish

Post by Sven »

lucasart wrote:g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -o ./sf *.cpp

But now I get the following problem:

/tmp/cclZS5J0.o: In function `init_threads':
/home/lucas/Downloads/src/search.cpp:2445: undefined reference to `pthread_create'

Finally I realized that compiling with

g++ -O3 -lpthread -o ./sf *.cpp

works like a charm !

Thank you again, and sorry for my silly questions. I'm not familiar with make, but I guess learning it is a necessary pain if you ever want to do portable code and compile it in an industrialised fashion.
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -lpthread -o ./sf *.cpp

would have been better (but still not recommended). The way you did it created a different executable which is most probably bigger, slower, and plays weaker, simply since you left out "-fno-exceptions -fno-rtti -DNDEBUG -msse".

There is not much to learn about "make". The bigger "pain" is in fact not to use it IMO.

Sven
UncombedCoconut
Posts: 319
Joined: Fri Dec 18, 2009 11:40 am
Location: Naperville, IL

Re: compiling StockFish

Post by UncombedCoconut »

lucasart wrote:I re-downloaded a fresh copy of it and ran

make build ARCH=x86-32 > err.log

*** erro.log ***
make ARCH=x86-32 COMP=gcc config-sanity
make[1]: Entering directory `/home/lucas/Downloads/src'

[snip]
g++ -o stockfish application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o misc.o move.o movegen.o history.o movepick.o search.o piece.o position.o direction.o tt.o uci.o ucioption.o mersenne.o book.o bitbase.o san.o benchmark.o timeman.o -lpthread
make[1]: Leaving directory `/home/lucas/Downloads/src'

*** end of err.log ***

so it seems good and displays no errors. However I can't find the output file ./stockfish.
If the final command worked successfully (and the output seems to indicate that it did), it would be in /home/lucas/Downloads/src

A more explicit version of Marco's suggestion:
make clean
make build ARCH=x86-32 2>&1 > build.log

And an attempt to explain make:
Stockfish's Makefile includes a lot of code to decide on compiler flags. Yet its core job is simple: build each object after its dependencies. It differs as follows from a "g++ [flags] *.cpp" command:
* It compiles the source files, separately, until it has up-to-date object code for each file. It passes "-c" to g++, which tells it to output an (incomplete) object file (named by the "-o filename.o" flag).
* Once the object files are ready, it passes all of them to g++ to be linked. The "-o stockfish" flag tells g++ to create an output file named "stockfish" in the current directory (/home/lucas/Downloads/src)

Because make compiles your source files separately, and only when they change, it is an enormous time-saver for developers of projects with many source files. As such, I strongly suggest that you use it in your own project. You will quickly recover the time invested in learning it. :)

HTH
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: compiling StockFish

Post by Sven »

UncombedCoconut wrote:make build ARCH=x86-32 2>&1 > build.log
UNIX shell trap ... This will print the standard error output to the screen and only the (original) standard output into "build.log". The correct version (order is significant!) would be:

Code: Select all

make build ARCH=x86-32 > build.log 2>&1
even if this looks unusual.

This is valid for "sh", "ksh", "bash" at least but not for "csh", "tcsh" which have a different syntax and do not even allow separate redirection of stderr (use >& to redirect stdout+stderr together).

Sven