Discussion:
How To Configure for Android?
Jeffrey Walton
2013-10-07 18:56:57 UTC
Permalink
Hi All,

I'm trying to cross compile libxml2
(http://www.xmlsoft.org/downloads.html) for Android. libxml2 use
autotools.

I have a script the detects the Android NDK gear and sets the
environment, path, CPP, CC, CXX, AS, AR, LD, SYSROOT, etc. It works
great for projects such as Botan, Crypto++, Cryptlib, OpenSSL,
libcurl, etc. For example:

$ echo $CPP
arm-linux-androideabi-cpp
$ echo $CC
arm-linux-androideabi-gcc
$ echo $ANDROID_NDK_ROOT
/opt/android-ndk-r9
$ echo $ANDROID_SYSROOT
/opt/android-ndk-r9/platforms/android-14/arch-arm
$ echo $CFLAGS
--sysroot=/opt/android-ndk-r9/platforms/android-14/arch-arm
$ echo $PATH
/opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin:
/opt/android-sdk-macosx/tools/:/opt/android-sdk-macosx/platform-tools/:
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:
/opt/X11/bin:/usr/local/MacGPG2/bin
..

Building libxml2 is having some trouble. When I try to configure:

$ ./configure --host=arm --build=arm --with-sysroot=$ANDROID_SYSROOT
checking build system type... arm-unknown-none
checking host system type... arm-unknown-none
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for arm-gcc... arm-linux-androideabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in
`/Users/jwalton/libxml2-2.9.1':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details

When I check the log:

$ cat config.log
...
configure:3612: checking whether we are cross compiling
configure:3620: arm-linux-androideabi-gcc -o conftest
--sysroot=/opt/android-ndk-r9/platforms/android-14/arch-arm
conftest.c >&5
configure:3624: $? = 0
configure:3631: ./conftest
./configure: line 3633: ./conftest: cannot execute binary file
configure:3635: $? = 126
configure:3642: error: in `/Users/jwalton/libxml2-2.9.1':
configure:3644: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details

I'm not sure why I'm trying to trick the build system with host=arm
since the host is x86_64. And it feels like I am not specifying the
target properly, but `configure --help` does not list any target
configuration options. Even with a `--host=arm`, configure is telling
me to specify a cross compile with `--host`.

I feel like I'm taking stabs in the dark with libxml2. Google is not
being very helpful because the leading dash (i.e., --host) means the
term should be excluded from the search terms.

Would someone be kind and tell me precisely what I should be supplying
to `config`?

Thanks in advance,

Jeff
Eric Blake
2013-10-07 19:05:12 UTC
Permalink
Post by Jeffrey Walton
$ ./configure --host=arm --build=arm --with-sysroot=$ANDROID_SYSROOT
configure:3644: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
I'm not sure why I'm trying to trick the build system with host=arm
since the host is x86_64.
You're lying. You're telling configure that your compiler is on an
arm-based host, when it is really on an x86_64-based host. Because your
--host and --build match, configure then assumes that you are not
cross-compiling. To cross-compile, --host and --build MUST be
different. Don't lie to configure. Try

./configure --host=x86_64 --build=arm

or even better, use full target triples, as in:

./configure --host=x86_64-unknown-linux-gnu --build=...

(I don't know the target triple for an android system, unfortunately).
Post by Jeffrey Walton
And it feels like I am not specifying the
target properly, but `configure --help` does not list any target
configuration options.
config.guess will show you a reasonable guest for host (there's a bug
request that we shouldn't require explicit --host any more, now that
we've had years of config.guess doing it right - but that's a story for
another thread and a future autoconf release; it would still be years
before you could ever assume all packages have been retooled to avoid
needing an explicit --host); and reading config.sub will show you all
the known triples that GNU software has tried to target.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Jeffrey Walton
2013-10-07 19:31:49 UTC
Permalink
Thanks Eric,
Post by Eric Blake
Post by Jeffrey Walton
I'm not sure why I'm trying to trick the build system with host=arm
since the host is x86_64.
You're lying. You're telling configure that your compiler is on an
arm-based host, when it is really on an x86_64-based host.
OK, thanks.
Post by Eric Blake
(I don't know the target triple for an android system, unfortunately).
Yeah, neither do I (for Mac OS X or Android).

For others who stumble upon this thread:

1) Set your PATH so the Android NDK tools (arm-linux-androideabi-cpp,
arm-linux-androideabi-gcc, and friends) are on PATH:

$ echo $PATH
/opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin:
/opt/android-sdk-macosx/tools/:/opt/android-sdk-macosx/platform-tools/:
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:
/opt/X11/bin:/usr/local/MacGPG2/bin

2) Ensure ANDROID_NDK_ROOT is set (this is an Android requirement, see
https://groups.google.com/d/msg/android-ndk/qZjhOaynHXc/Szy_KYY9GcwJ):

$ echo $ANDROID_NDK_ROOT
/opt/android-ndk-r9

3) Export the tools:
export CPP=arm-linux-androideabi-cpp
export CC=arm-linux-androideabi-cc
...
export LD=arm-linux-androideabi-ld
...

4) Export CPPFLAGS, CFLAGS, and CXXFLAGS *with* SYSROOT (some
autotools tests don't honor the config option):
$ echo $ANDROID_SYSROOT
/opt/android-ndk-r9/platforms/android-14/arch-arm
export CPPFLAGS="--sysroot=$ANDROID_SYSROOT"
export CFLAGS="--sysroot=$ANDROID_SYSROOT"
export CXXFLAGS="--sysroot=$ANDROID_SYSROOT"

5) Configure as follows (`--build=arm-android` breaks config):

$ ./configure --host=x86_64-darwin --build=arm --with-sysroot=$ANDROID_SYSROOT
checking build system type... arm-unknown-none
checking host system type... x86_64-pc-none
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes

I owe you a beer or two if you make it to Maryland.

Jeff
Post by Eric Blake
Post by Jeffrey Walton
$ ./configure --host=arm --build=arm --with-sysroot=$ANDROID_SYSROOT
configure:3644: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
I'm not sure why I'm trying to trick the build system with host=arm
since the host is x86_64.
You're lying. You're telling configure that your compiler is on an
arm-based host, when it is really on an x86_64-based host. Because your
--host and --build match, configure then assumes that you are not
cross-compiling. To cross-compile, --host and --build MUST be
different. Don't lie to configure. Try
./configure --host=x86_64 --build=arm
./configure --host=x86_64-unknown-linux-gnu --build=...
(I don't know the target triple for an android system, unfortunately).
Post by Jeffrey Walton
And it feels like I am not specifying the
target properly, but `configure --help` does not list any target
configuration options.
config.guess will show you a reasonable guest for host (there's a bug
request that we shouldn't require explicit --host any more, now that
we've had years of config.guess doing it right - but that's a story for
another thread and a future autoconf release; it would still be years
before you could ever assume all packages have been retooled to avoid
needing an explicit --host); and reading config.sub will show you all
the known triples that GNU software has tried to target.
Eric Blake
2013-10-07 19:51:01 UTC
Permalink
Post by Jeffrey Walton
Thanks Eric,
Post by Eric Blake
Post by Jeffrey Walton
I'm not sure why I'm trying to trick the build system with host=arm
since the host is x86_64.
You're lying. You're telling configure that your compiler is on an
arm-based host, when it is really on an x86_64-based host.
OK, thanks.
Post by Eric Blake
(I don't know the target triple for an android system, unfortunately).
Yeah, neither do I (for Mac OS X or Android).
But you DO know it :)
Post by Jeffrey Walton
export CPP=arm-linux-androideabi-cpp
export CC=arm-linux-androideabi-cc
Your --target triple is therefore:

arm-linux-androideabi

Autoconf-based configure files by default will attempt to use
$TRIPLE-cc, without you having to export CC and lots of other variables,
if you just tell it the right --target name, and if all of your cross
toolchain is consistently named as $TRIPLE-tool.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Zack Weinberg
2013-10-08 02:33:07 UTC
Permalink
Wait wait wait. --target is only supposed to be necessary if you're
*building a cross compiler*, innit? And I think you have --build and
--host backward. My understanding is that what Jeffrey wants is

./configure --build=`./config.guess` --host=arm-linux-androideabi [...]

zw
Post by Eric Blake
Post by Jeffrey Walton
Thanks Eric,
Post by Eric Blake
Post by Jeffrey Walton
I'm not sure why I'm trying to trick the build system with host=arm
since the host is x86_64.
You're lying. You're telling configure that your compiler is on an
arm-based host, when it is really on an x86_64-based host.
OK, thanks.
Post by Eric Blake
(I don't know the target triple for an android system, unfortunately).
Yeah, neither do I (for Mac OS X or Android).
But you DO know it :)
Post by Jeffrey Walton
export CPP=arm-linux-androideabi-cpp
export CC=arm-linux-androideabi-cc
arm-linux-androideabi
Autoconf-based configure files by default will attempt to use
$TRIPLE-cc, without you having to export CC and lots of other variables,
if you just tell it the right --target name, and if all of your cross
toolchain is consistently named as $TRIPLE-tool.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
_______________________________________________
Autoconf mailing list
https://lists.gnu.org/mailman/listinfo/autoconf
Eric Blake
2013-10-08 03:45:57 UTC
Permalink
Post by Zack Weinberg
Wait wait wait. --target is only supposed to be necessary if you're
*building a cross compiler*, innit? And I think you have --build and
--host backward. My understanding is that what Jeffrey wants is
./configure --build=`./config.guess` --host=arm-linux-androideabi [...]
Yes, I probably got things backward, because I wrote my email without
consulting the manual.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Loading...