Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] NDK 23.0 with CMake 3.21: "clang++ is not able to compile a simple test program" #1560

Closed
Boris-Rasin opened this issue Aug 13, 2021 · 4 comments
Labels

Comments

@Boris-Rasin
Copy link


Description

Build error:

    [2/2] Linking CXX executable cmTC_3a497
    FAILED: cmTC_3a497 
    cmd.exe /C "cd . && C:\Users\admin\AppData\Local\Android\Sdk\ndk\23.0.7599858\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=x86_64-none-linux-android16 --sysroot=C:/Users/admin/AppData/Local/Android/Sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -frtti -stdlib=libc++  -O2 -g -DNDEBUG -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Qunused-arguments -Wl,--no-undefined  -Wl,--gc-sections CMakeFiles/cmTC_3a497.dir/testCXXCompiler.cxx.o -o cmTC_3a497  -static-libstdc++ -latomic -lm && cd ."
    ld: error: cannot open crtbegin_dynamic.o: No such file or directory
    ld: error: unable to find library -lc++
    ld: error: cannot open crtend_android.o: No such file or directory
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

Defining ANDROID_USE_LEGACY_TOOLCHAIN_FILE=ON fixes the problem.

Test case:
https://github.com/scapix-com/example1
Open folder ui/android
Remove ANDROID_USE_LEGACY_TOOLCHAIN_FILE=ON to see the error.

Environment Details

  • NDK version: 23.0.7599858
  • Build system: CMake 3.21.1
  • Host OS: Windows, macOS
@DanAlbert
Copy link
Member

Reduced test case (CMake must be 3.21+):

$ cat ./foo.cpp
int main(int argc, char** argv) {
  return 0;
}
$ cat ./CMakeLists.txt
cmake_minimum_required(VERSION 3.6.0)

add_executable(foo foo.cpp)
$ cat ./build.sh
#!/bin/sh
if [ $# -lt 1 ]; then
  >&2 echo "usage: ./build.sh NDK_PATH"
  exit 1
fi

set -e

NDK_PATH=$(realpath $1)

cd "$(dirname "$0")"
rm -rf build
mkdir build
cd build
cmake \
  -GNinja \
  -DANDROID_ABI=x86_64 \
  -DANDROID_PLATFORM=android-16 \
  -DCMAKE_TOOLCHAIN_FILE=$NDK_PATH/build/cmake/android.toolchain.cmake \
  ${@:2} ..

ninja -v

The difference is that our toolchain was automatically pulling up android-16 to android-21 for LP64 targets. AGP doesn't do that, nor does CMake. I'm not sure if we can work around that or if AGP just needs to stop asking for configurations that don't exist.

Triaged to r23b to at least figure that out. If it requires an AGP fix we probably need to disable it by default for a year or so while AGP catches up.

@DanAlbert
Copy link
Member

It looks like the new toolchain doesn't do any of the API level clamping the old one did. I'm guessing that wasn't intentional.

ViliusSutkus89 added a commit to opendocument-app/pdf2htmlEX-Android that referenced this issue Aug 26, 2021
@DanAlbert
Copy link
Member

The fix needed a fix: https://android-review.googlesource.com/c/platform/ndk/+/1826816/. Whoever does the cherry-picks make sure you get both :)

chenguoyin-alibaba pushed a commit to riscv-android-src/platform-ndk that referenced this issue Oct 21, 2021
Test: added test
Bug: android/ndk#1560
Change-Id: If5fbba07e1c3630ef1b2766c684288ca07294ff6
(cherry picked from commit 29519e9)
chenguoyin-alibaba pushed a commit to riscv-android-src/platform-ndk that referenced this issue Oct 21, 2021
When not specified this was evaluating to an empty string, so CMake
was receiving only one argument...

Test: added a test
Bug: android/ndk#1560
Change-Id: I1340a7b0afd271568c5f8aadbc4ca345479e95fa
(cherry picked from commit eaaf499)
@rprichard
Copy link
Collaborator

Fixed in r23b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants