From f9fc1499a3f8d951704dbc7f71be03ad326af117 Mon Sep 17 00:00:00 2001 From: Huang weiliang Date: Thu, 18 Jul 2024 19:15:22 -0400 Subject: [PATCH] Create 2024-07-17-android_build_C.md --- _posts/2024-07-17-android_build_C.md | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 _posts/2024-07-17-android_build_C.md diff --git a/_posts/2024-07-17-android_build_C.md b/_posts/2024-07-17-android_build_C.md new file mode 100644 index 00000000000..cf4a4498455 --- /dev/null +++ b/_posts/2024-07-17-android_build_C.md @@ -0,0 +1,39 @@ +--- +layout: post +title: "Manually cross compile a program for android" +subtitle: "Get rid of the android build system" +header-img: img/post-bg-coffee.jpeg +date: 2024-07-17 08:00:00 +author: half cup coffee +catalog: true +tags: + - Android +--- + +# Cross compile a programm for android + +Android build system will compole all the software components includes the kernel, native libraries and so on. Normally if we are going to add a native program we need follow the android rules to add the makefile Android.bp or Android.mk. If the program only consist of several source files or even single file. It is easy for us to add the android makefile for it. But sometimes we want to port opensource program to android which it might include hundreds of source files and many sub folders, also need feature configuration before we compile it. + +Normally for a cross compile we just need specify the cross compiler and the sysroot then we can build a program. We want the compile for android can be as simple as this way. So here give a guidence for that purpose: + +``` +export TOOLCHAIN=/PROJECT_ROOT/prebuilts/ndk-r23/toolchains/llvm/prebuilt/linux-x86_64/ +export TARGET=aarch64-linux-android +export API=23 +export AR=$TOOLCHAIN/bin/llvm-ar +export CC=$TOOLCHAIN/bin/$TARGET$API-clang +export AS=$CC +export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++ +export LD=$TOOLCHAIN/bin/ld +export RANLIB=$TOOLCHAIN/bin/llvm-ranlib +export STRIP=$TOOLCHAIN/bin/llvm-strip + +##In case there is autogen.sh: +./autogen.sh --enable-tools=yes --host=$TARGET --with-sysroot=$TOOLCHAIN/sysroot --prefix=xxxxx + +##In case there is configure: +./configure --host=$TARGET --with-sysroot=$TOOLCHAIN/sysroot --prefix=xxxxx + +make +make install +```