【问题标题】:how to compile jrtplib with android ndk 20如何使用 android ndk 20 编译 jrtplib
【发布时间】:2019-08-28 10:31:07
【问题描述】:

我正在尝试使用最新的 NDK (20) 编译 https://github.com/j0r1/JRTPLIB,但按照 github 自述文件中提供的说明(可以很好地使用 NDK 17 编译 jrtplib)失败并出现以下错误:

构建机器是 Gentoo Linux,并尝试使用 cmake-3.14 和 3.15(没有改变)

CMake Deprecation Warning at CMakeLists.txt:5 (cmake_policy):
   The OLD behavior for policy CMP0026 will be removed from a future version
   of CMake.
   The cmake-policies(7) manual explains that the OLD behaviors of all
   policies are deprecated and that a policy should be set to OLD only under
   specific short-term circumstances.  Projects should be ported to the NEW
   behavior and not rely on setting a policy to OLD.



 CMake Error at /home/franci/prog/vdk-deps/android/cmake/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:60 (message):
   The C compiler

     "/home/franci/Apps/android-ndk-r20//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/franci/prog/vdk-deps/android/jrtplib-3.9.1/CMakeFiles/CMakeTmp

     Run Build Command(s):/usr/bin/gmake cmTC_78e13/fast && /usr/bin/gmake -f CMakeFiles/cmTC_78e13.dir/build.make CMakeFiles/cmTC_78e13.dir/build
     gmake[1]: Entering directory '/home/franci/prog/vdk-deps/android/jrtplib-3.9.1/CMakeFiles/CMakeTmp'
     Building C object CMakeFiles/cmTC_78e13.dir/testCCompiler.c.o
     /home/franci/Apps/android-ndk-r20//toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=aarch64-none-linux-android --gcc-toolchain=/home/franci/Apps/android-ndk-r20//toolchains//prebuilt/linux-x86_64 --sysroot=/home/franci/Apps/android-ndk-r20//sysroot  -isystem
 /home/franci/Apps/android-ndk-r20/sysroot/usr/include -isystem /home/franci/Apps/android-ndk-r20/sysroot/usr/include/aarch64-linux-android  -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=21 -fexceptions  -g -fPIE   -o CMakeFiles/cmTC_78e13.dir/testCCompiler.c.o   -c
 /home/franci/prog/vdk-deps/android/jrtplib-3.9.1/CMakeFiles/CMakeTmp/testCCompiler.c
     Linking C executable cmTC_78e13
     /home/franci/prog/vdk-deps/android/cmake/bin/cmake -E cmake_link_script CMakeFiles/cmTC_78e13.dir/link.txt --verbose=1
     /home/franci/Apps/android-ndk-r20//toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=aarch64-none-linux-android --gcc-toolchain=/home/franci/Apps/android-ndk-r20//toolchains//prebuilt/linux-x86_64
 --sysroot=/home/franci/Apps/android-ndk-r20//platforms/android-21/arch-arm64 -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=21 -fexceptions  -g  -Wl,--gc-sections  CMakeFiles/cmTC_78e13.dir/testCCompiler.c.o  -o cmTC_78e13
     /usr/bin/ld: unrecognised emulation mode: aarch64linux
     Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om elf_k1om
     clang: error: linker command failed with exit code 1 (use -v to see invocation)
     gmake[1]: *** [CMakeFiles/cmTC_78e13.dir/build.make:87: cmTC_78e13] Error

看来 cmake 没有选择正确的 LD(实际上它似乎指向 /usr/bin/ld)

按照自述文件中的建议,我使用的编译命令是:

#!/bin/bash

if [ $# -lt "2" ]; then
    echo "Usage: ${0} TOOLCHAIN_FILE_FULLPATH INSTALL_PATH"
    echo " i.e. ${0} ./toolchain.cmake.arm64 /opt/android/install"
    exit 1
fi

TOOLCHAIN_FILE=$1
INSTALL_PATH=$2
ccmake -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE} \
       -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} \
       -DCMAKE_FIND_ROOT_PATH=${INSTALL_PATH} \
       -DCMAKE_LINKER=/home/franci/Apps/android-ndk-r20/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/ld \
       ./CMakeLists.txt

将以下 toolchain.file 传递给 ndk 17 和安装路径 有效

set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 23) # API level
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
set(CMAKE_ANDROID_NDK /home/franci/Apps/android-sdk/ndk-bundle/)
set(CMAKE_ANDROID_STL_TYPE gnustl_static)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

this toolchain.file 传递给 ndk 20 和安装路径 工作

set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 23) # API level
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
set(CMAKE_ANDROID_NDK /home/franci/Apps/android-ndk-r20/)
set(CMAKE_ANDROID_STL_TYPE c++_shared)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

【问题讨论】:

  • 也许你打过this CMake bug
  • @Michael 谢谢,通过夜间构建,我设法编译了它。如果您想发布答案,我会接受。

标签: c++ cmake android-ndk


【解决方案1】:

使用 NDK 本身提供的工具链文件会更好地为您服务。查看文档:https://developer.android.com/ndk/guides/cmake#the_cmake_toolchain_file

【讨论】:

    【解决方案2】:

    你需要 DCMAKE_TOOLCHAIN_FILE ${HOME}/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake

    【讨论】:

      猜你喜欢
      • 2013-12-10
      • 2014-05-03
      • 2011-10-25
      • 1970-01-01
      • 2011-02-25
      • 1970-01-01
      • 1970-01-01
      • 2014-02-14
      • 2011-08-15
      相关资源
      最近更新 更多