official-stockfish / Stockfish

A free and strong UCI chess engine
https://stockfishchess.org/
GNU General Public License v3.0
11.33k stars 2.25k forks source link

Error android compilation. #2524

Closed Alexei1981 closed 4 years ago

Alexei1981 commented 4 years ago

Builds for android fails after adding this patch. Here is the error (compiled with ndk-r17, default compiler - clang-7). Then I checked with Clang-9, the same thing)

misc.cpp:306:10: error: use
      of undeclared identifier
      'aligned_alloc'
  *mem = aligned_alloc
Alexei1981 commented 4 years ago

I tried to build stockfish arm64 using gcc-7.5, exactly the same error. This c ++ 17 insert does not work on android.

Alexei1981 commented 4 years ago

Compiler output (clang-9). It has been tested on GCC-7.5, GCC-9.2, Clang-7) Everywhere the same mistake.

Config:
debug: 'no'
sanitize: 'no'
optimize: 'yes'
arch: 'armv8'
bits: '64'
kernel: ''
os: 'Android'
prefetch: 'no'
popcnt: 'yes'
sse: 'no'
pext: 'no'

Flags:
CXX: clang++
CXXFLAGS: -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE
LDFLAGS:    -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE -fPIE -pie

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

make ARCH=armv8 COMP=clang all
make[1]: Entering directory '/home/src'
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o benchmark.o benchmark.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o bitbase.o bitbase.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o bitboard.o bitboard.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o endgame.o endgame.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o evaluate.o evaluate.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o main.o main.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o material.o material.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o misc.o misc.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o movegen.o movegen.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o movepick.o movepick.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o pawns.o pawns.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o position.o position.cpp
misc.cpp:306:10: error: use of
      undeclared identifier
      'aligned_alloc'
  *mem = aligned_alloc(al...
         ^
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o psqt.o psqt.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT  -DUSE_POPCNT -flto -fPIE   -c -o search.o search.cpp
1 error generated.
make[1]: *** [<builtin>: misc.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/home/src'
make: *** [Makefile:415: build] Error 2
snicolet commented 4 years ago

Thanks for the report!

Two questions:

1) @vondele Have we tried compiling the last master with clang on Linux+PC (not clang on Linux+Android, where we know it fails)?

2) @Alexei1981 Can you try changing line 300 of misc.h on you machine to the following, and see if it compiles?

#if defined(__linux__) && !defined(__ANDROID__)
vondele commented 4 years ago

@snicolet what's Linux+PC ? clang on Linux + x86 works (that's in CI).

Your suggestion will of course work... so seemingly aligned_alloc is not available on android, despite this being iso c11?

Alexei1981 commented 4 years ago

@snicolet It works. misc.cpp line 300

#if defined(__linux__) && !defined(__ANDROID__)
make build COMP=clang ARCH=armv8 -j7

Config:
debug: 'no'
sanitize: 'no'
optimize: 'yes'
arch: 'armv8'
bits: '64'
kernel: 'Linux'
os: 'Android'
prefetch: 'yes'
popcnt: 'yes'
sse: 'no'
pext: 'no'

Flags:
CXX: clang++
CXXFLAGS: -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE
LDFLAGS:    -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE -fPIE -pie

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

make ARCH=armv8 COMP=clang all
make[1]: Entering directory '/home/src'
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o benchmark.o benchmark.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o bitbase.o bitbase.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o bitboard.o bitboard.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o endgame.o endgame.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o evaluate.o evaluate.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o main.o main.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o material.o material.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o misc.o misc.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o movegen.o movegen.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o movepick.o movepick.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o pawns.o pawns.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o position.o position.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o psqt.o psqt.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o search.o search.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o thread.o thread.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o timeman.o timeman.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o tt.o tt.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o uci.o uci.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o ucioption.o ucioption.cpp
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE   -c -o syzygy/tbprobe.o syzygy/tbprobe.cpp
clang++ -o stockfish benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o search.o thread.o timeman.o tt.o uci.o ucioption.o syzygy/tbprobe.o    -Wall -Wcast-qual -fno-exceptions -std=c++11  -pedantic -Wextra -Wshadow  -DNDEBUG -O3 -march=armv8-a -DIS_64BIT -DUSE_POPCNT -flto -fPIE -fPIE -pie
make[1]: Leaving directory '/home/src'
WOnder93 commented 4 years ago

Your suggestion will of course work... so seemingly aligned_alloc is not available on android, despite this being iso c11?

When you are compiling in C++ mode, the C standard is not what matters. In C++, this function is only part of the standard since C++17. See:

JavaMast commented 4 years ago

@Alexei1981 can you please confirm that fix work only with misc.cpp line 300 and not with misc.cpp line 50 see pull request https://github.com/official-stockfish/Stockfish/pull/2530/files

Alexei1981 commented 4 years ago

@JavaMast Of course works with the 50 + 300 line in misc.cpp. Although if you fix only line 300, then this also works.

vondele commented 4 years ago

thanks for the report!

If you could contribute to the wiki or the open issues wrt. compilation on android that would be much appreciated. Eventually we need CI setup for this platform so that these kind of mistakes don't get noticed so late in the process.