2

I am trying to build an arm64 version of libcurl 7.50.3, using android NDK r13b, targeting Android API 19. I've managed to get armv7 working, but I keep getting errors with arm64. These are my export flags:

NDK_ROOT="/opt/android-ndk-r13b"
export SYSROOT="${NDK_ROOT}/platforms/android-19/arch-arm"
export CPPFLAGS="-I${SYSROOT}/usr/include --sysroot=${SYSROOT}"
export CFLAGS="--sysroot=${SYSROOT}"
export CC=$(${NDK_ROOT}/ndk-which gcc)
export LD=$(${NDK_ROOT}/ndk-which ld)
export CPP=$(${NDK_ROOT}/ndk-which cpp)
export CXX=$(${NDK_ROOT}/ndk-which g++)
export AS=$(${NDK_ROOT}/ndk-which as)
export AR=$(${NDK_ROOT}/ndk-which ar)
export RANLIB=$(${NDK_ROOT}/ndk-which ranlib)

And my configure call

LIBS="-ldl -lssl -lcrypto" ./configure \
--disable-ftp \
--disable-file \
--disable-ldap \
--disable-dict \
--disable-telnet \
--disable-gopher \
--disable-tftp \
--disable-manual \
--disable-shared \
--disable-imap \
--disable-pop3 \
--disable-rtsp \
--disable-smb \
--disable-smtp \
--enable-threaded-resolver \
--enable-ipv6 \
--with-ssl=${SSL_DIR} \
--host=aarch64-linux-android \
--target=aarch64-linux-android \

And then make. I've tried with host and target set to arm-linux-androideabi as well, but I keep getting the same error. The config.log says

configure:4488: ./conftest
./configure: line 4490: ./conftest: cannot execute binary file: Exec format error
configure:4492: $? = 126
configure:4499: error: in `/home/sossisos/build_curl_android/curl_7.50.3':
configure:4501: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details

Am I missing something? Have I misunderstood what target or host to use?

jww
  • 97,681
  • 90
  • 411
  • 885
Sossisos
  • 1,569
  • 2
  • 10
  • 19
  • When using Autotools, I believe you need to use `--target` for a cross-compile. `--host` is the machine you are building on. If Host=Target (you are building on Aarch64 machine), then don't specify either one. `--target=aarch64-linux-android` may *not* be a valid target, and `--host=aarch64-linux-android` is probably wrong. As far as I know, [there's no way to get Autotools to tell you the valid triplets](https://lists.gnu.org/archive/html/autoconf/2015-02/msg00006.html). Also see [Cross Compiling For ARM With Autoconf](http://stackoverflow.com/q/15234959). – jww Dec 30 '16 at 21:09
  • 4
    That's incorrect. --build is the system you're running on, --host is the system you want the compiled program to run on, and --target is use to *build* cross-compilers. See my old blog post at https://blog.flameeyes.eu/2009/01/the-canonical-target/ for the full explanation. – Diego Elio Pettenò Dec 31 '16 at 08:36
  • In addition to what Diego said, you also need to change `SYSROOT` to point to `android-21/arch-arm64`, for linking to succeed. (This doesn't matter for supporting API 19 on the other architectures; there are no arm64 devices running anything less than API 21 since the ABI appeared in that version.) – mstorsjo Dec 31 '16 at 10:54

1 Answers1

4

Make sure you invoke ./configure with both --host (set to arm64/android) and --build (set to your system, likely x86_64-pc-linux-gnu). The latter should be autodetected, but it's not always so. This way the script will know you're cross-compiling and it won't be trying to execute the programs it built.

Diego Elio Pettenò
  • 3,152
  • 12
  • 15