Boost and NDK r5

2,740 views
Skip to first unread message

Nicolas Zerr

unread,
Dec 13, 2010, 10:17:31 AM12/13/10
to android-ndk
Hello,

I would like to compile Boost 1.45 with the NDK r5, since it embedds
now full stl support.
But I have very few informations on how to compile it, even for
previous versions of NDK.

I tried to modify the tools/build/v2/user-config.jam file, without
success.
It seems that I cannot link with standard library and stl.

Here is my user-config.jam :

# -----------------
# Android configuration.
# -----------------

NDK = /home/skuld/projects/skuld/android/android-ndk-r5 ;
using gcc : android4.4.0 : $(NDK)/toolchains/arm-eabi-4.4.0/prebuilt/
linux-x86/bin/arm-eabi-g++ :
<cxxflags>-I$(NDK)/platforms/android-9/arch-arm/usr/include
<cflags>-nostdlib
<cxxflags>--sysroot=$(NDK)/platforms/android-9/arch-arm
<cxxflags>-DBOOST_THREAD_LINUX
<cxxflags>-DBOOST_HAS_PTHREADS
<cxxflags>-D__arm__
<cxxflags>-D_REENTRANT
<cxxflags>-D_GLIBCXX__PTHREADS
<linkflags>-lc
<linkflags>-Wl,-rpath-link=$(NDK)/platforms/android-9/arch-arm/usr/
lib/
<linkflags>-L$(NDK)/platforms/android-9/arch-arm/usr/lib
<linkflags>$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-
x86/arm-linux-androideabi/lib/libsupc++.a
<linkflags>$NDK/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/lib/gcc/
arm-eabi/4.4.0/libgcc.a
<linkflags>$NDK/platforms/android-9/arch-arm/usr/lib/libstdc++.so
<linkflags>$NDK/platforms/android-9/arch-arm/usr/lib/libc.so
<linkflags>$NDK/platforms/android-9/arch-arm/usr/lib/libm.so
<linkflags>-Wl,--no-undefined
<linkflags>-Wl,--whole-archive
<linkflags>-Wl,--no-whole-archive
<linkflags>-Wl,-shared,-Bsymbolic
;

I don't know if all the flags are correct but i'm sure of the paths.

Here is an example of the output errors :
...patience...
...found 505 targets...
...updating 12 targets...
gcc.compile.c++ bin.v2/libs/date_time/build/gcc-android4.4.0/release/
threading-multi/gregorian/greg_month.o
In file included from ./boost/date_time/gregorian/greg_month.hpp:12,
from libs/date_time/src/gregorian/greg_month.cpp:14:
./boost/date_time/constrained_value.hpp:12:21: error: exception: No
such file or directory
./boost/date_time/constrained_value.hpp:13:21: error: stdexcept: No
such file or directory
In file included from ./boost/config.hpp:40,
from ./boost/date_time/constrained_value.hpp:14,
from ./boost/date_time/gregorian/greg_month.hpp:12,
from libs/date_time/src/gregorian/greg_month.cpp:14:
./boost/config/select_stdlib_config.hpp:17:19: error: cstddef: No such
file or directory
In file included from ./boost/config/select_stdlib_config.hpp:33,
from ./boost/config.hpp:40,
from ./boost/date_time/constrained_value.hpp:14,
from ./boost/date_time/gregorian/greg_month.hpp:12,
from libs/date_time/src/gregorian/greg_month.cpp:14:
./boost/config/no_tr1/utility.hpp:21:21: error: utility: No such file
or directory
In file included from ./boost/smart_ptr/shared_ptr.hpp:27,
from ./boost/shared_ptr.hpp:17,
from ./boost/date_time/gregorian/greg_month.hpp:14,
from libs/date_time/src/gregorian/greg_month.cpp:14:
./boost/config/no_tr1/memory.hpp:21:20: error: memory: No such file or
directory
In file included from ./boost/smart_ptr/detail/
sp_counted_base_spin.hpp:21,
from ./boost/smart_ptr/detail/sp_counted_base.hpp:66,
from ./boost/smart_ptr/detail/shared_count.hpp:29,
from ./boost/smart_ptr/shared_ptr.hpp:32,
from ./boost/shared_ptr.hpp:17,
from ./boost/date_time/gregorian/greg_month.hpp:14,
from libs/date_time/src/gregorian/greg_month.cpp:14:
./boost/detail/sp_typeinfo.hpp:109:20: error: typeinfo: No such file
or directory

By the way, is there an other way to make boost build, for instance
create anAndroid.mk for each module of boost (I suppose it would be a
huge task) ?

Igor R

unread,
Dec 13, 2010, 2:23:50 PM12/13/10
to andro...@googlegroups.com

It looks like the build system doesn't see Boost root... If you add
<cxxflags>-I/full/path/to/Boost does it help?

Nicolas Zerr

unread,
Dec 14, 2010, 2:46:35 AM12/14/10
to android-ndk
Hello,

It does not change anything. Actually, it is the same output whithout
any cxx flags.

alan

unread,
Dec 14, 2010, 4:18:29 AM12/14/10
to android-ndk
The following was tested with boost 1.45:
userconfig.jam:
import os ;

if [ os.name ] = CYGWIN || [ os.name ] = NT
{
androidPlatform = windows ;
}
else if [ os.name ] = LINUX
{
androidPlatform = linux-x86 ;
}
else if [ os.name ] = MACOSX
{
androidPlatform = darwin-x86 ;
}

androidNDKRoot = ../android-ndk ;
using gcc : android4.4.3 :
$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$
(androidPlatform)/bin/arm-linux-androideabi-g++ :
<compileflags>--sysroot=$(androidNDKRoot)/platforms/android-3/arch-
arm
<compileflags>-mthumb
<compileflags>-Os
<compileflags>-fno-strict-aliasing
<compileflags>-O2
<compileflags>-DNDEBUG
<compileflags>-g
<compileflags>-lstdc++
<compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/
include
<compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/
libs/armeabi/include
<compileflags>-D__GLIBC__
<compileflags>-DBOOST_NO_INTRINSIC_WCHAR_T
<archiver>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ar
<ranlib>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ranlib
;

for boost asio:
modify boost\asio\detail\fenced_block.hpp, change 2 instances of:
#elif defined(__GNUC__) && defined(__arm__)
to:
#elif defined(__GNUC__) && defined(__arm__) && !defined(__ANDROID__)
modify boost\asio\detail\socket_types.hpp, add:
#ifdef __ANDROID__
#ifndef INET_ADDRSTRLEN
#define INET_ADDRSTRLEN 16
#endif
#ifndef INET6_ADDRSTRLEN
#define INET6_ADDRSTRLEN 46
#endif
#endif
modify boost\asio\ip\address_v6.hpp, add:
#ifdef __ANDROID__
#ifndef IN6ADDR_ANY_INIT
#define IN6ADDR_ANY_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
#endif
#ifndef IN6_IS_ADDR_MULTICAST
#define IN6_IS_ADDR_MULTICAST(addr) (((const uint8_t *) (addr))[0]
== 0xff)
#endif
#ifndef IN6_IS_ADDR_MC_NODELOCAL
#define IN6_IS_ADDR_MC_NODELOCAL(addr) \
(IN6_IS_ADDR_MULTICAST(addr) \
&& (((const uint8_t *)(addr))[1] & 0xf) == 0x1)
#endif
#ifndef IN6_IS_ADDR_MC_GLOBAL
#define IN6_IS_ADDR_MC_GLOBAL(addr) \
(IN6_IS_ADDR_MULTICAST(addr) \
&& (((const uint8_t *)(addr))[1] & 0xf) == 0xe)
#endif
#endif
modify libs\filesystem\v2\src\v2_operations.cpp, change:
# if !defined(__APPLE__) && !defined(__OpenBSD__)
# include <sys/statvfs.h>
# define BOOST_STATVFS statvfs
# define BOOST_STATVFS_F_FRSIZE vfs.f_frsize
# else
#ifdef __OpenBSD__
# include <sys/param.h>
#endif
to:
# if !defined(__APPLE__) && !defined(__OpenBSD__) && !
defined(__ANDROID__)
# include <sys/statvfs.h>
# define BOOST_STATVFS statvfs
# define BOOST_STATVFS_F_FRSIZE vfs.f_frsize
# else
#ifdef __OpenBSD__
# include <sys/param.h>
#elif defined(__ANDROID__)
# include <sys/vfs.h>
#endif

then build with:
./bjam --without-python --without-math --without-mpi --without-
iostreams toolset=gcc-android4.4.3 link=static runtime-link=static
target-os=linux --stagedir=android stage
this builds the following libraries:
libboost_date_time.a
libboost_filesystem.a
libboost_graph.a
libboost_program_options.a
libboost_random.a
libboost_regex.a
libboost_serialization.a
libboost_signals.a
libboost_system.a
libboost_thread.a
libboost_wave.a
note that date time to and from string will not work due to the
locales issue mentioned elsewhere in this group

Nicolas Zerr

unread,
Dec 14, 2010, 1:14:03 PM12/14/10
to android-ndk
Thank you, it worked!
By the way, can the other libraries be built, even with tricks?

alan

unread,
Dec 15, 2010, 4:49:01 AM12/15/10
to android-ndk
I don't know, the above libraries are the ones that either work
unmodified or are required by our project. I havent tried the others
but i'm sure if you try them you will quickly find out if they work or
not, if they don't it will probably be easy to fix most issues

Igor R

unread,
Dec 15, 2010, 4:56:15 AM12/15/10
to andro...@googlegroups.com
> Thank you, it worked!
> By the way, can the other libraries be built, even with tricks?

Note that most of Boost libraries are header-only, and you don't have
to build them. So the above list of built libraries includes almost
all the libs, which need to be built.

sdy7

unread,
Dec 17, 2010, 4:17:25 AM12/17/10
to android-ndk
Hi

I'm only using the header-only libs in boost, and need not compile.
But what is the proper way of building ndk projects with boost? Before
I used r4-crystax
and it worked by just copying the boost header folder into the
platform includes.
Now I get errors like
/boost/smart_ptr/detail/shared_count.hpp:102: error: 'bad_alloc' is
not a member of 'std'

cheers
sdy7

Justin Holewinski

unread,
Dec 17, 2010, 9:50:37 AM12/17/10
to andro...@googlegroups.com

Copying extra files into the NDK platform directory is not really a good idea.  It is best to keep the boost headers as part of your project or in a separate directory and include the path in your android.mk file as a -I compiler flag.  Also, some parts of boost may require exceptions and rtti, so you should use the gnustl_static STL implementation.  Just add a line like APP_STL := gnustl_static to your Application.mk file.

> cheers
> sdy7
>
> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>

Nasif Noorudeen

unread,
Dec 18, 2010, 12:46:05 PM12/18/10
to andro...@googlegroups.com
i am not sure you can succesfuuly compile boost with andoid -ndk 5  even of it have stl support
use android-ndk r4-crystax with all support for boost , since i am not sure c++ excption is handled in android-ndk r5
pleas

Justin Holewinski

unread,
Dec 18, 2010, 1:31:10 PM12/18/10
to andro...@googlegroups.com
On Sat, Dec 18, 2010 at 12:46 PM, Nasif Noorudeen <nas...@gmail.com> wrote:
i am not sure you can succesfuuly compile boost with andoid -ndk 5  even of it have stl support
use android-ndk r4-crystax with all support for boost , since i am not sure c++ excption is handled in android-ndk r5
pleas

That's why you need to use the "APP_STL := gnustl_static" flag in your Application.mk file.  This uses the GNU STL implementation which does support exceptions and RTTI, unlike the other STL implementations that come with the NDK.



--

Thanks,

Justin Holewinski

Afriza N. Arief

unread,
Dec 20, 2010, 2:59:57 AM12/20/10
to andro...@googlegroups.com
On Sun, Dec 19, 2010 at 2:31 AM, Justin Holewinski <justin.h...@gmail.com> wrote:
On Sat, Dec 18, 2010 at 12:46 PM, Nasif Noorudeen <nas...@gmail.com> wrote:
i am not sure you can succesfuuly compile boost with andoid -ndk 5  even of it have stl support
use android-ndk r4-crystax with all support for boost , since i am not sure c++ excption is handled in android-ndk r5
pleas

That's why you need to use the "APP_STL := gnustl_static" flag in your Application.mk file.  This uses the GNU STL implementation which does support exceptions and RTTI, unlike the other STL implementations that come with the NDK.
 

Other thread reports that using gnustl_static may cause your app to work only on Android 2.2+ and when using crystax, it should run on Android 2.0.1+

Tim Mensch

unread,
Dec 20, 2010, 8:38:06 PM12/20/10
to andro...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/20/2010 12:59 AM, Afriza N. Arief wrote:
> Other thread reports that using gnustl_static may cause your app to work
> only on Android 2.2+ and when using crystax, it should run on Android 2.0.1+

Crystax works all the way back to (at least) 1.5.

Still waiting on upgrading to r5 for verification that it WILL work at
least back to 1.6.

Tim
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNEAT+AAoJENSbqLBCyKKsnsYH/AkVzKCEBe2iPRLHXwV558ed
5Ij8cS5HEJQTy6f6bIJiTrtS6Ey926/tY1kmFZ4aXnYCrCNXmyUc01jI7h0dP6SC
KOfQOmx7dIr0S9QsFzBYxa/x2SEHf8u7wlf8wqfDeBqJ4WqvttSO379/IyNilSHH
T+TKlJKNhacP2iaiMZTUfE3yKn9nrqcimv5hpiMsKk3WWXm+mEkKuTSHrbvUMjMp
IrTJiuVMxDh5CrmGjYgpKHwx78EaZ+i/SdaW4x/QAJjquePc90fNJ4P8flFK505c
sTidn11j3yHryqQz3+2AmIuCZU9xE4tkhn0nmbDrIyN4nBNwFZ8D0M0xoXYdm7c=
=mla7
-----END PGP SIGNATURE-----

David Turner

unread,
Dec 21, 2010, 5:25:42 AM12/21/10
to andro...@googlegroups.com
Looking at your config file, you are still using the old (now deprecated arm-eabi-4.4.0) toolchain.
GNU libstdc++ support is only provided through the new toolchain (arm-linux-androideabi-4.4.3). Maybe changing your configuration file to use that instead should work.
 

alan

unread,
Dec 21, 2010, 8:07:52 AM12/21/10
to android-ndk
I am using boost with ndk 5 and apart from locales issues I can
confirm that it works correctly with android 1.6

On Dec 21, 10:25 am, David Turner <di...@android.com> wrote:
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages