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
compiling StockFish
Moderators: hgm, chrisw, Rebel
-
- Posts: 2684
- Joined: Sat Jun 14, 2008 9:17 pm
Re: compiling StockFish
Please post the full compile output, you know, I have lost my crystal balllucasart 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
BTW try:
make build ARCH=x86-32
-
- Posts: 3238
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: compiling StockFish
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
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
-
- Posts: 2684
- Joined: Sat Jun 14, 2008 9:17 pm
Re: compiling StockFish
What I need is the head of the error log, please post here the first 50 lines and compile with:lucasart wrote:Actually I can't see it ending!
make build ARCH=x86-32
-
- Posts: 3238
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: compiling StockFish
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.
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.
-
- Posts: 2684
- Joined: Sat Jun 14, 2008 9:17 pm
Re: compiling StockFish
You have redirected stdout not stderrlucasart 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
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.
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: compiling StockFish
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?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
EDIT: Saw the recent replies too late, sorry. So it seems I found the same as you did already ...
Sven
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: compiling StockFish
g++ -g -Wall -Wcast-qual -ansi -fno-exceptions -fno-rtti -pedantic -Wno-long-long -Wextra -DNDEBUG -O3 -msse -lpthread -o ./sf *.cpplucasart 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.
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
-
- Posts: 319
- Joined: Fri Dec 18, 2009 11:40 am
- Location: Naperville, IL
Re: compiling StockFish
If the final command worked successfully (and the output seems to indicate that it did), it would be in /home/lucas/Downloads/srclucasart 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.
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
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: compiling StockFish
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:UncombedCoconut wrote:make build ARCH=x86-32 2>&1 > build.log
Code: Select all
make build ARCH=x86-32 > build.log 2>&1
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