Objective
This is a series of articles made up of "compiling a glib library to run on Android" and 4 other articles, which are listed in the "Compiling dependent Libraries" section of the 4 articles. Since the glib library relies on other third-party libraries, it is necessary to cross-compile the dependent third-party libraries onto the Android platform to successfully compile the glib library, in addition to compiling the glib library that can be run on Android Other cross-compilation articles are all about how to cross-compile a glib dependent library. Above, so called series articles, because these articles complete the introduction of how to compile glib libraries that can run on Android.
Article value
The core value of these articles is the cross-compilation experience of the Android platform and provides a new way to compile. Some people have migrated the Linux library to Android and translated the makefile into a android.mk file (as far as I know), and using the methods in this article can be used to cross-compile the original makefile file directly.
Compiling the environment
This article cross-compiles the glib project on Ubuntu 64-bit systems.
Conventions
The "NDK" below refers to "Android NDK" without any special instructions.
Step 1. Download and install the Android NDK
The process of downloading and installing the Android NDK is not introduced here.
Download Gitlib
2. Install the necessary tools
- GNU autoconf 2.62
- GNU automake 1.11
- GNU Libtool 2.2
- GNU GetText 0.10.40
- Pkg-config 0.16
- Gtk-doc
- Libffi 3.0.0
For the tools to be installed to compile the glib project, refer to the hacking file under the glib source root directory.
3. Setting NDK and Sysroot environment variables setting NDK environment variables
The "$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin" directory contains the ARM-LINUX-ANDROIDEABI-GCC, Cross-compiling tools such as arm-linux-androideabi-g++, but the path of the cross-compilation tool varies depending on the NDK version and the version of the compilation tool.
Setting Sysroot Environment variables
Sysroot represents a directory in which the target's system header files and libraries are included, and the target represents the ARM CPU architecture in the context of current contexts. The "android-21" in the path represents the Android API level, where 21 represents the Android5.0.1.
Resources
This article uses the Android NDK tool for cross-compiling, Google's official reference: Standalone toolchain, which details how to use the Android NDK tool for cross-compiling.
4. Compiling dependent libraries
Libiconv
Version: 1.14
Compiling reference: Compiling a libiconv library that can run on Android
GetText
Version: 0.19.7
Compiling reference: Compiling a gettext library that can run on Android
Pcre
Version: 8.38
Compiling reference: Compiling a pcre library that can run on Android
Libffi
Version: 3.2.1
Compiling reference: Compiling a libffi library that can run on Android
5. Writing Android.cache
Create the Android.cache file in the root directory of the glib source, and write the following in the file:
GLIB official reference for the cache file: cross-compiling the GLib package.
6. Running autogen.sh
In the glib source root directory, enter the command:
When the script executes successfully, a script file named "Configure" is generated.
7. Running Configure
This error will be reported if you do not add CPP and cppflags: "Configure:error:c preprocessor"/lib/cpp "Fails sanity check".
The value of the--host option, "Arm-linux-androideabi", is expanded in the Configure script to compile tool names such as "ARM-LINUX-ANDROIDEABI-GCC".
8. Compiling and installing
Use the make command to compile the source code, when the compilation is successful using the "Do Install" command to install, LIBICONV will be installed in the ${sysroot}/usr/lib directory, in the above "--prefix=" ${SYSROOT}/USR " The command option is used to specify the directory for the installation.
Wrong Rowconfigure.ac:88:error:possibly undefined Macro:ac_define
Problem
This is a very vague question. I compiled glib when I installed the Automake, Libtool tools, but still prompt this error.
Solutions
I installed these tools to solve this approach: Autoconf,automake,autopoint,pkg-config.
But it is not clear what libraries have been installed to solve this problem.
Solution Source Post:
1, M Cross Bug 2 glib Build Fail #799: https://github.com/mxe/mxe/issues/799
2, http://mxe.cc/#requirements-debian
Compile to run the series on Android:
Compiling a dependent library that can run on Android (i): GLib library
Compiling a dependent library that can run on Android (ii): GetText Library
Compiling a dependent library that can run on Android (iii): Libffi Library
Compiling a dependent library that can run on Android (iv): LIBICONV Library
Compiling a dependent library that can run on Android (v): Pcre Library
Search Yu Ali Mobile Security, more technical articles, please visit the Ali Poly Security Blog
Series | Compiling a dependent library that can run on Android (i): GLib library