android - CMake Android交叉编译:clang总是尝试与gcc工具链链接
问题描述
我正在尝试将我的 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)
我注意到两个意想不到的行为:
- 虽然我指定
CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION
为clang,但它仍然想使用 GCC 库。 - 尽管我指定了 C 和 CXX 工具链前缀,但它仍然无法找到 binutils 例如
CMAKE_OBJDUMP
,CMAKE_STRIP
,CMAKE_OBJCOPY
,CMAKE_NM
。
那么我应该如何让一切正常工作呢?
解决方案
推荐阅读
- java - 如何在 graphql-java-tools Resolver 中 @Autowire 一个 JPA 存储库
- java - Java:无限循环 hasNextInt()
- python - pd.read_sql 方法来计算大型 Access 数据库中的行数
- c++ - 为什么 .idl 文件中使用的 `cpp_quote` 和 `pragma midl_echo` 不向 C++/WinRT 项目中生成的标头输出任何内容?
- xamarin.forms - 跨平台 Xamarin 表单应用程序 - 未显示 Android 启动画面
- javascript - 打字稿更改对象属性值动态错误
- flutter - 如何在 Flutter 的 Column 中使用带有 ListView 的扩展磁贴
- java - ArrayList.removeAll(Collection<>) 是否关心重复项?
- r - R:如何在测试结果和警告时从测试报告中省略测试警告消息
- javascript - appendChild 或 prepend 导致 SELECT 项目重新排序