Skip to content

Instantly share code, notes, and snippets.

@enh
Last active July 19, 2023 00:19
Show Gist options
  • Save enh/b2dc8e2cbbce7fffffde2135271b10fd to your computer and use it in GitHub Desktop.
Save enh/b2dc8e2cbbce7fffffde2135271b10fd to your computer and use it in GitHub Desktop.
Shell script to build boost for Android
#!/bin/bash
version=1.68.0
echo "Building boost $version..."
set -eu
toolchain=$PWD/toolchain
if [ ! -d "$toolchain" ]; then
echo "Building toolchain..."
$ANDROID_NDK_ROOT/build/tools/make-standalone-toolchain.sh \
--arch=arm --platform=android-21 \
--install-dir="$toolchain" \
--toolchain=arm-linux-androideabi-clang \
--use-llvm --stl=libc++
else
echo "Toolchain already built"
fi
dir_name=boost_$(sed 's#\.#_#g' <<< $version)
archive=${dir_name}.tar.bz2
if [ ! -f "$archive" ]; then
wget -O $archive "https://dl.bintray.com/boostorg/release/$version/source/$archive"
else
echo "Archive $archive already downloaded"
fi
echo "Extracting..."
if [ ! -d "$dir_name" ]; then
# rm -rf $dir_name
tar xf $archive
else
echo "Archive $archive already unpacked into $dir_name"
fi
cd $dir_name
echo "Generating config..."
user_config=tools/build/src/user-config.jam
rm -f $user_config
cat <<EOF > $user_config
import os ;
using clang : android
:
"$toolchain/bin/clang++"
:
<archiver>$toolchain/bin/arm-linux-androideabi-ar
<ranlib>$toolchain/bin/arm-linux-androideabi-ranlib
;
EOF
echo "Bootstrapping..."
./bootstrap.sh #--with-toolset=clang
echo "Building..."
./b2 -j32 \
--with-atomic \
--with-chrono \
--with-container \
--with-date_time \
--with-exception \
--with-fiber \
--with-filesystem \
--with-graph \
--with-graph_parallel \
--with-iostreams \
--with-locale \
--with-log \
--with-math \
--with-mpi \
--with-program_options \
--with-random \
--with-regex \
--with-serialization \
--with-signals \
--with-system \
--with-test \
--with-thread \
--with-timer \
--with-type_erasure \
--with-wave \
toolset=clang-android \
architecture=arm \
variant=release \
--layout=versioned \
target-os=android \
threading=multi \
threadapi=pthread \
link=static \
runtime-link=static \
echo "Running ranlib on libraries..."
libs=$(find "bin.v2/libs/" -name '*.a')
for lib in $libs; do
"$toolchain/bin/arm-linux-androideabi-ranlib" "$lib"
done
echo "Done!"
@yakir22
Copy link

yakir22 commented Jan 7, 2019

For anyone who might be interested in building boost for Android with c++17 support you can add the following
<cxxflags>-std=c++17
just above the line in the script
<archiver>$toolchain/bin/arm-linux-androideabi-ar

@grand87
Copy link

grand87 commented Dec 10, 2019

Thank you - works great for 1.68
I was trying to use this script to build 1.71 version - failed in

/home/v.sharayenko/boost_1_71_0/tools/build/src/tools/common.jam:983: in toolset-tag
*** argument error
* rule numbers.less ( n1 n2 )
* called with: ( 3 )
* missing argument n2

@las33
Copy link

las33 commented Feb 7, 2020

Component configuration:

    - atomic                   : building
    - chrono                   : building
    - container                : building
    - context                  : not building
    - contract                 : not building
    - coroutine                : not building
    - date_time                : building
    - exception                : building
    - fiber                    : building
    - filesystem               : building
    - graph                    : building
    - graph_parallel           : building
    - iostreams                : building
    - locale                   : building
    - log                      : building
    - math                     : building
    - mpi                      : building
    - program_options          : building
    - python                   : not building
    - random                   : building
    - regex                    : building
    - serialization            : building
    - signals                  : building
    - stacktrace               : not building
    - system                   : building
    - test                     : building
    - thread                   : building
    - timer                    : building
    - type_erasure             : building
    - wave                     : building

...patience...
...patience...
...patience...
...patience...
...patience...
...found 10925 targets...
...updating 362 targets...
clang-linux.compile.c++.without-pth bin.v2\libs\atomic\build\clang-linux-android\release\architecture-arm\link-static\target-os-android\threading-multi\lockpool.o
The system cannot find the path specified.

  "/c/Users/las3/Downloads/code/1/toolchain/bin/clang++" -c -x c++ -std=c++17 -O3 -Wall -Wno-inline  -DBOOST_ALL_NO_LIB=1 -DBOOST_ATOMIC_SOURCE -DBOOST_ATOMIC_STATIC_LINK=1 -DNDEBUG -I"." -o "bin.v2\libs\atomic\build\clang-linux-android\release\architecture-arm\link-static\target-os-android\threading-multi\lockpool.o" "libs\atomic\src\lockpool.cpp"

Anyone can help me please?

@dec1
Copy link

dec1 commented Jul 25, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment