CMake Android交叉编译:clang始终尝试与gcc工具链链接

时间:2019-09-27 03:50:46

标签: android cmake clang cross-compiling

我正在尝试将CMake项目构建为Android平台。我使用了CMake 3.12.3和ninja 1.9.0,下面是我使用的工具链文件:

set(CMAKE_SYSTEM_NAME "Android")
set(CMAKE_ANDROID_NDK "C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570")
set(CMAKE_ANDROID_ARCH_ABI "arm64-v8a")
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION "clang")
set(CMAKE_ANDROID_STL_TYPE "c++_static")
set(CMAKE_SYSROOT "${CMAKE_ANDROID_NDK}/platforms/android-24/arch-arm64")
set(CMAKE_C_ANDROID_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64/aarch64-linux-android")
set(CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64/aarch64-linux-android")

在配置阶段失败:

Android: Targeting API '24' with architecture 'arm64', ABI 'arm64-v8a', and processor 'aarch64'
Android: Selected Clang toolchain 'aarch64-linux-android-clang' with GCC toolchain ''
The C compiler identification is Clang 8.0.7
The CXX compiler identification is Clang 8.0.7
Check for working C compiler: C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
Check for working C compiler: C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570/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: D:/projects/MyProject-android-arm64-ninja/CMakeFiles/CMakeTmp

    Run Build Command:"D:/development/ninja-1.9.0/ninja.exe" "cmTC_70fcb"
    [1/2] Building C object CMakeFiles/cmTC_70fcb.dir/testCCompiler.c.o

    [2/2] Linking C executable cmTC_70fcb

    FAILED: cmTC_70fcb 

    cmd.exe /C "cd . && C:\Users\myname\AppData\Local\Android\Sdk\ndk\20.0.5594570\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe --target=aarch64-none-linux-android --gcc-toolchain=C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains//prebuilt/windows-x86_64 --sysroot=C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570/platforms/android-24/arch-arm64 -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=24 -fexceptions  -g  -fPIE -pie -Wl,--gc-sections CMakeFiles/cmTC_70fcb.dir/testCCompiler.c.o  -o cmTC_70fcb   && cd ."

    ld: error: unable to find library -lgcc

    ld: error: unable to find library -lgcc

    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    ninja: build stopped: subcommand failed.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)

我注意到了两个意外行为:

  1. 尽管我为 clang 指定了CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION,但它仍然希望使用GCC库。
  2. 尽管我指定了C和CXX工具链前缀,但仍然找不到诸如CMAKE_OBJDUMPCMAKE_STRIPCMAKE_OBJCOPYCMAKE_NM之类的binutils。

那我应该如何使一切正常?

0 个答案:

没有答案
相关问题