使用 Android 工具链与 autoconf 交叉编译

Cross Compile with autoconf with Android toolchain

Objective 使用 NDK 工具链为 Android 交叉编译 Cisco libsrtp 并使用 libsrtp.a 静态 link 反对我自己的图书馆。

设置 : 我使用以下文件

<setup.sh>
  export CROSS_SYSROOT=/home/psurana/aa/sysroot
  export CROSS_COMPILE=aarch64-linux-android-
  export SYSROOT=/home/psurana/aa/sysroot
  export CC="${CROSS_COMPILE}gcc  --sysroot=${SYSROOT}"
  export CXX="${CROSS_COMPILE}gxx --sysroot=${SYSROOT}" 
  PATH=/home/psurana/aa/bin:$PATH

然后我进行以下配置:

source setup.sh && ./configure --host=aarch64-linux-android --build=`./config.guess` && make -j

这是为我编译的。做一个 readelf -h libsrtp.a,产量--

File: libsrtp.a(ut_sim.o)
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           AArch64
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          1480 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           64 (bytes)
  Number of section headers:         10
  Section header string table index: 7

到目前为止一切顺利。

问题

但是,当我 link libsrtp.a 作为预建静态库时,出现以下错误:

./srtp/libsrtp.a(rand_source.o): In function `rand_source_init':

err.c:(.text+0x0): undefined reference to `stdout'
err.c:(.text+0xc): undefined reference to `stdout'

并且

rand_source.c:(.text+0x28): undefined reference to `stderr'
rand_source.c:(.text+0x3c): undefined reference to `stderr'

我的理解是Android的libc中没有stderr,那么libsrtp是怎么得到这些的呢?

我之前使用类似的东西构建了相同的库,我知道它可以构建。我不知道可能是什么错误。

我通常会在 21 之后在任何平台上使用 libc 获得这个未定义的引用,所以我通常将 -D__ANDROID_API__=21 添加到 CFLAGS 并最终修复它。我相信这个问题来自新的统一 headers 在较新的 ndk 版本中。