Thank you for your reply. I tried rc4, and now I can’t even get past compiler detection. Then I re-read the docs again, and I think I was doing something wrong before: I should not be using CMAKE_ANDROID_STANDALONE_TOOLCHAIN if I want to get a Visual Studio project, as that doesn’t seem to be supported. However, if I try to generate a project using CMAKE_ANDROID_TOOLCHAIN, it also doesn’t work (with the same errors as https://gitlab.kitware.com/cmake/cmake/-/issues/24290).
I’m trying to understand if this is NDK, Visual Studio, or CMake issue. Running cmake .. -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE=C:/Microsoft/AndroidNDK/android-ndk-r23c/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a
produces the following output:
CMake Warning (dev) at CMakeLists.txt:20 (project):
cmake_minimum_required() should be called prior to this top-level project()
call. Please see the cmake-commands(7) manual for usage documentation of
both commands.
This warning is for project developers. Use -Wno-dev to suppress it.
-- ANDROID_PLATFORM not set. Defaulting to minimum supported version
16.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Microsoft/AndroidNDK/android-ndk-r23c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: C:/Microsoft/AndroidNDK/android-ndk-r23c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.27/Modules/CMakeTestCCompiler.cmake:67 (message):
The C compiler
"C:/Microsoft/AndroidNDK/android-ndk-r23c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: 'I:/dd2_reborn/allegro.git/build_ndr/CMakeFiles/CMakeScratch/TryCompile-oqcq6v'
Run Build Command(s): "C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe" cmTC_56b2a.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:n
MSBuild version 17.6.3+07e294721 for .NET Framework
Build started 02.07.2023 19:48:15.
Project "I:\dd2_reborn\allegro.git\build_ndr\CMakeFiles\CMakeScratch\TryCompile-oqcq6v\cmTC_56b2a.vcxproj" on node 1 (default targets).
SetBuildDefaultEnvironmentVariables:
ANDROID_HOME=C:\ProgramData\Microsoft\AndroidSDK\25
ANDROID_SDK_ROOT=C:\ProgramData\Microsoft\AndroidSDK\25
ANT_HOME=
JAVA_HOME=C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08
NDK_ROOT=C:\\Microsoft\AndroidNDK\android-ndk-r23c
PrepareForBuild:
Creating directory "cmTC_56b2a.dir\Debug\".
Creating directory "I:\dd2_reborn\allegro.git\build_ndr\CMakeFiles\CMakeScratch\TryCompile-oqcq6v\Debug\".
Creating directory "cmTC_56b2a.dir\Debug\cmTC_56b2a.tlog\".
InitializeBuildStatus:
Creating "cmTC_56b2a.dir\Debug\cmTC_56b2a.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\\Microsoft\AndroidNDK\android-ndk-r23c\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe -c -fdiagnostics-format=msvc --gcc-toolchain="C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\x86_64-4.9\\prebuilt\\windows-x86_64" -target "x86_64-none-linux-android1" --sysroot="C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot" -isystem "C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot\\usr\\include\\x86_64-linux-android" -isystem "C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\lib64\\clang\\12.0.9\\include" -isystem "C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\sources\\android\\support\\include" -isystem "C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot\\usr\\include" -I "C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\sources\\cxx-stl\\llvm-libc++\\include" -I "C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\sources\\cxx-stl\\llvm-libc++abi\\include" -I "C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot\\usr\\include" -I "C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot\\usr\\include\\x86_64-linux-android" -I "C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\sources\\android\\support\\include" -I "C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\lib64\\clang\\12.0.9\\include" -gline-tables-only -o "cmTC_56b2a.dir\\Debug\\testCCompiler.o" -Wall -O3 -fno-strict-aliasing -fomit-frame-pointer -fno-exceptions -ffunction-sections -fdata-sections -fstack-protector -fpic -fno-short-enums -D __ANDROID_API__=1 -D NDEBUG -D ANDROID -D _FORTIFY_SOURCE=2 -D "CMAKE_INTDIR=\"Debug\"" -x c -g -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wformat -Werror=format-security -fno-limit-debug-info "I:\\dd2_reborn\\allegro.git\\build_ndr\\CMakeFiles\\CMakeScratch\\TryCompile-oqcq6v\\testCCompiler.c"
testCCompiler.c
In file included from <built-in>:352:
<command line>(1,9): warning : '__ANDROID_API__' macro redefined [-Wmacro-redefined] [I:\dd2_reborn\allegro.git\build_ndr\CMakeFiles\CMakeScratch\TryCompile-oqcq6v\cmTC_56b2a.vcxproj]
#define __ANDROID_API__ 1
^
<built-in>(345,9): note: previous definition is here
#define __ANDROID_API__ __ANDROID_MIN_SDK_VERSION__
^
1 warning generated.
Link:
C:\\Microsoft\AndroidNDK\android-ndk-r23c\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe -fdiagnostics-format=msvc -o"cmTC_56b2a.dir\\Debug\\cmTC_56b2a." -Wl,-soname="cmTC_56b2a." -Wl,-rpath-link="C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot\\usr\\lib\\x86_64-linux-android" -Wl,-rpath-link="C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot\\usr\\lib\\x86_64-linux-android\\1" -Wl,-L"C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot\\usr\\lib\\x86_64-linux-android" -Wl,-L"C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot\\usr\\lib\\x86_64-linux-android\\1" -Wl,-L"C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\x86_64-4.9\\prebuilt\\windows-x86_64\\lib\\gcc\\x86_64-linux-android\\4.9.x" -Wl,-L"C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\sources\\cxx-stl\\llvm-libc++\\libs\\x86_64" -Wl,--no-undefined --gcc-toolchain="C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\x86_64-4.9\\prebuilt\\windows-x86_64" -target "x86_64-none-linux-android1" --sysroot="C:\\\\Microsoft\\AndroidNDK\\android-ndk-r23c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot" -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -shared -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,--gc-sections cmTC_56b2a.dir\\Debug\\testCCompiler.o "-latomic" "-lm" -lc++_static -lc++abi -llog -landroid
ld: error: cannot open crtbegin_so.o: No such file or directory
ld: error: unable to find library -llog
ld: error: unable to find library -landroid
ld: error: cannot open crtend_so.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Application Type\Android\3.0\Android.Common.targets(125,5): error MSB6006: "clang.exe" exited with code 1. [I:\dd2_reborn\allegro.git\build_ndr\CMakeFiles\CMakeScratch\TryCompile-oqcq6v\cmTC_56b2a.vcxproj]
Done Building Project "I:\dd2_reborn\allegro.git\build_ndr\CMakeFiles\CMakeScratch\TryCompile-oqcq6v\cmTC_56b2a.vcxproj" (default targets) -- FAILED.
Build FAILED.
"I:\dd2_reborn\allegro.git\build_ndr\CMakeFiles\CMakeScratch\TryCompile-oqcq6v\cmTC_56b2a.vcxproj" (default target) (1) ->
(ClCompile target) ->
<command line>(1,9): warning : '__ANDROID_API__' macro redefined [-Wmacro-redefined] [I:\dd2_reborn\allegro.git\build_ndr\CMakeFiles\CMakeScratch\TryCompile-oqcq6v\cmTC_56b2a.vcxproj]
"I:\dd2_reborn\allegro.git\build_ndr\CMakeFiles\CMakeScratch\TryCompile-oqcq6v\cmTC_56b2a.vcxproj" (default target) (1) ->
(Link target) ->
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Application Type\Android\3.0\Android.Common.targets(125,5): error MSB6006: "clang.exe" exited with code 1. [I:\dd2_reborn\allegro.git\build_ndr\CMakeFiles\CMakeScratch\TryCompile-oqcq6v\cmTC_56b2a.vcxproj]
1 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.45
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:20 (project)
-- Configuring incomplete, errors occurred!
The gist of the problem seems to be the wrong triple for target architecture: the compiler check uses “sysroot\usr\lib\x86_64-linux-android” where actually it should use “sysroot\usr\lib\aarch64-linux-android”. Which is strange, because if I look at CMakeConfigureLog.yaml log, I see:
The target system is: Android - 1 - aarch64
The host system is: Windows - 10.0.19043 - AMD64
So it correctly detects aarch64 (from my ANDROID_ABI)… And proceeds to ignore it and try to use x86_64, and the fails to find system libraries.