【发布时间】:2020-03-03 09:33:49
【问题描述】:
我正在尝试为 Android 构建 Marble,一个用于地图和导航的 Qt 库。目前,我宁愿采用这种方式,也不愿使用 QtLocation 和 QML,因为我对 C++ 接口更满意。为此,我遵循本指南:https://community.kde.org/Marble/AndroidCompiling
我的规格如下:
VirtualBox VM 上的 Kali Linux(版本 2020.1,代号 kali-rolling)(是的,我知道我有点像个冷酷的混蛋……事实上,我在 Linux 上有点初学者,但是它提供的工具对我目前正在从事的项目很有用。此外,对于以前的项目,我已经安装了 Qt 和所需的 Android 工具,如下所述:https://doc.qt.io/qt-5/android-getting-started.html。
Qt 5.14.1 和 Qt Creator 4.11.1
Android Sdk:Android SDK 构建工具 30-rc1、LLDB、NDK(并排)、Android SDK 命令行工具(最新)、CMake、Android SDK 平台工具 (29.0.6)、 Android SDK Tools (Obsolete) (26.1.1) 但按照指南的指示将
Sdk/tools替换为 SDK Tools 版本 r25.2.5;安装 SDK 平台 10 和 20 至 29。Android Ndk:android-ndk-r21(最新下载)。 Sdk安装中有一个ndk文件夹(
Sdk/ndk/21.0.6113669/)不知道是不是一样,也不知道是不是同一个版本。无论如何,这对他们中的任何一个都不起作用。JDK:我已经安装了 openjdk 8 (
/usr/lib/jvm/java-8-openjdk-amd64),因为正如 QtCreator 所说,SDK 只能与“Java 1.8”一起使用。CMake:版本 3.16.3
Ant:版本 1.10.7
~/marble/sources中的 Marble 源和此文件夹中来自 KDE 的额外 cmake 模块~/kirigami中的剪纸
好的,从那里我按照指南,根据需要定义环境变量:
export ANDROID_NDK_ROOT=~/Android/android-ndk-r21
export ANDROID_NDK=$ANDROID_NDK_ROOT
export ANDROID_SDK_ROOT=~/Android/Sdk
export ANT=/usr/bin/ant
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export Qt5_android=/opt/Qt/5.14.1/android
export ECM=~/marble/sources/extra-cmake-modules
export ANDROID_PLATFORM=android-29
那是当我从~/kirigami/build 运行以下命令时无法使用 cmake 进行配置:
cmake .. -DCMAKE_TOOLCHAIN_FILE=${ECM}/toolchain/Android.cmake -DCMAKE_PREFIX_PATH=${Qt5_android} -DCMAKE_INSTALL_PREFIX=~/marble/export -DECM_DIR=/usr/local/share/ECM/cmake
我收到以下错误:
-- You can export a target by specifying -DQTANDROID_EXPORTED_TARGET=<targetname> and -DANDROID_APK_DIR=<paths>
-- Android: Targeting API '21' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a'
-- You can export a target by specifying -DQTANDROID_EXPORTED_TARGET=<targetname> and -DANDROID_APK_DIR=<paths>
-- Android: Selected unified Clang toolchain
-- The C compiler identification is Clang 9.0.8
-- The CXX compiler identification is Clang 9.0.8
-- Check for working C compiler: /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/kali/kirigami/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_be61f/fast && /usr/bin/make -f CMakeFiles/cmTC_be61f.dir/build.make CMakeFiles/cmTC_be61f.dir/build
make[1]: Entering directory '/home/kali/kirigami/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi21 --sysroot=/home/kali/Android/android-ndk-r21/sysroot -march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=21 -fexceptions -g -fPIE -o CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o -c /home/kali/kirigami/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_be61f
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_be61f.dir/link.txt --verbose=1
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi21 --sysroot=/home/kali/Android/android-ndk-r21/platforms/android-21/arch-arm -march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=21 -fexceptions -g -Wl,--fix-cortex-a8 -fPIE -pie -Wl,--gc-sections -Wl,-z,nocopyreloc CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o -o cmTC_be61f -latomic -lm
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lunwind
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lunwind
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [CMakeFiles/cmTC_be61f.dir/build.make:87: cmTC_be61f] Error 1
make[1]: Leaving directory '/home/kali/kirigami/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_be61f/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:6 (project)
-- Configuring incomplete, errors occurred!
See also "/home/kali/kirigami/build/CMakeFiles/CMakeOutput.log".
See also "/home/kali/kirigami/build/CMakeFiles/CMakeError.log".
这里是CMakeOutput.log:
The target system is: Android - 21 - armv7-a
The host system is: Linux - 5.4.0-kali3-amd64 - x86_64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
Build flags:
Id flags:
The output was:
0
Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.out"
The C compiler identification is Clang, found in "/home/kali/kirigami/build/CMakeFiles/3.16.3/CompilerIdC/a.out"
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
Build flags:
Id flags:
The output was:
0
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"
The CXX compiler identification is Clang, found in "/home/kali/kirigami/build/CMakeFiles/3.16.3/CompilerIdCXX/a.out"
还有CMakeError.log:
Determining if the C compiler works failed with the following output:
Change Dir: /home/kali/kirigami/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_be61f/fast && /usr/bin/make -f CMakeFiles/cmTC_be61f.dir/build.make CMakeFiles/cmTC_be61f.dir/build
make[1]: Entering directory '/home/kali/kirigami/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi21 --sysroot=/home/kali/Android/android-ndk-r21/sysroot -march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=21 -fexceptions -g -fPIE -o CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o -c /home/kali/kirigami/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_be61f
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_be61f.dir/link.txt --verbose=1
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi21 --sysroot=/home/kali/Android/android-ndk-r21/platforms/android-21/arch-arm -march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=21 -fexceptions -g -Wl,--fix-cortex-a8 -fPIE -pie -Wl,--gc-sections -Wl,-z,nocopyreloc CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o -o cmTC_be61f -latomic -lm
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lunwind
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lunwind
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [CMakeFiles/cmTC_be61f.dir/build.make:87: cmTC_be61f] Error 1
make[1]: Leaving directory '/home/kali/kirigami/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_be61f/fast] Error 2
因此,某些链接器似乎存在问题,无法找到 libunwind 或类似的东西。我曾尝试安装运行 sudo apt install libunwind-dev 的 libunwind 作为第一个猜测,但这并没有解决任何问题。我对 cmake、链接等不够了解和查明问题,我在网上找不到任何有关此问题的有用信息。你能帮帮我吗?
【问题讨论】:
-
在您的主机系统上安装 libunwind 没有帮助,因为您正在交叉编译,因此您需要为您的目标平台安装或构建 libunwind。但是,我认为这是一个环境问题。我会尝试针对 API android-28(而不是 21),使用不同的 NDK(即 19c)重建,最后切换到 debian 或任何其他受支持的发行版,因为 Kali linux 不是。此外,尝试在 Android Studio 中运行 NDK 示例之一将有助于查明问题。
标签: android c++ linux qt cmake