STLport on android

118 views
Skip to first unread message

Richard Zhao

unread,
May 20, 2009, 11:44:00 PM5/20/09
to android-ndk
Hi All,

I'm porting things to android. but android doesn't have stl support.
Has anyone managed to use stlport in android?

stlport in google gears said it have android support, but I didn't
found any Android.mk.
Anyone ever tried to build it?

Thanks
Richard

Tomei Ningen

unread,
May 21, 2009, 1:23:10 AM5/21/09
to andro...@googlegroups.com
I tried building STLport for Android using the a combination of (a) the code from google gear and (b) the latest version of STLport. I got it to built but some of the tests got stuck while running inside Android emulator. Worse, my target app just crashed.

The problem is Android's native GCC doesn't support exceptions and rtti/dynamic_cast. So if you have an app that uses STL, it's very likely that it also wants exceptions and rtti.

(I think STLport itself also uses exceptions and rtti, but I don't remember clearly).

So in order to build my app, I hacked out all the try/catch, and changed all dynamic_cast to static_cast. Of course, the result is it crashes.

For now, my "solution" is to use CodeSourcery gcc compiler and statically link in the standard c++ library. It adds about 1MB of static footprint, but that's acceptable for now considering the price of flash and the amount that's available .... a lot of that 1MB has to do with locale/formatting money, etc. I guess if I am really short on space I will just hack the libstdc++.a and replace the unnecessary functions with empty stubs.

John Ripley

unread,
May 30, 2009, 10:29:19 AM5/30/09
to android-ndk
Hi Richard,

I'm the author of the STLport modifications in Gears. There's no
Android.mk because the way it's done is that you only have to add it
in your include path and set a few defines. This is deliberately to
avoid adding a lot to the binary size, but in hindsight I could have
arranged to built it as a library and then let the linker do garbage
collection. I've since managed to build it like this, but as there's
no real advantage to any application I have, I've not pursued it
further.

The only problems with using STLport as just include files are the
lack of iostreams, rtti and exceptions. However, rtti/exceptions is a
bigger problem than just STLport as it needs a toolchain change, and
few libraries use iostreams anyway, so it was enough to just support
the containers and algorithms.

If you copy the appropriate flags from the Gears makefiles: the -
I*stlport* and -D_STLP* lines, that should be sufficient to compile
your app. You don't actually need to compile and of the .cc/.cpp files
in STLport to get it working.

Richard Zhao

unread,
May 31, 2009, 11:05:09 PM5/31/09
to andro...@googlegroups.com, jri...@google.com
Hi John,

Thank you very much. See my comments below.

On Sat, May 30, 2009 at 10:29 PM, John Ripley <jri...@google.com> wrote:
>
> Hi Richard,
>
> I'm the author of the STLport modifications in Gears. There's no
> Android.mk because the way it's done is that you only have to add it
> in your include path and set a few defines. This is deliberately to
> avoid adding a lot to the binary size, but in hindsight I could have
> arranged to built it as a library and then let the linker do garbage
> collection. I've since managed to build it like this, but as there's
> no real advantage to any application I have, I've not pursued it
> further.
>
> The only problems with using STLport as just include files are the
> lack of iostreams, rtti and exceptions. However, rtti/exceptions is a
> bigger problem than just STLport as it needs a toolchain change, and
> few libraries use iostreams anyway, so it was enough to just support
> the containers and algorithms.
>
> If you copy the appropriate flags from the Gears makefiles: the -
> I*stlport* and -D_STLP* lines, that should be sufficient to compile
> your app. You don't actually need to compile and of the .cc/.cpp files
> in STLport to get it working.
Which make file do I need to copy "-I*stlport* and -D_STLP*" from ?
And, I don't understand, if I only include head files of function
declares, how could it link to function implementions?

Thanks
Richard

John Ripley

unread,
Jun 2, 2009, 6:07:43 AM6/2/09
to Richard Zhao, andro...@googlegroups.com

2009/6/1 Richard Zhao <linu...@gmail.com>

Hi John,

Thank you very much. See my comments below.

On Sat, May 30, 2009 at 10:29 PM, John Ripley <jri...@google.com> wrote:
>
> Hi Richard,
>
> I'm the author of the STLport modifications in Gears. There's no
> Android.mk because the way it's done is that you only have to add it
> in your include path and set a few defines. This is deliberately to
> avoid adding a lot to the binary size, but in hindsight I could have
> arranged to built it as a library and then let the linker do garbage
> collection. I've since managed to build it like this, but as there's
> no real advantage to any application I have, I've not pursued it
> further.
>
> The only problems with using STLport as just include files are the
> lack of iostreams, rtti and exceptions. However, rtti/exceptions is a
> bigger problem than just STLport as it needs a toolchain change, and
> few libraries use iostreams anyway, so it was enough to just support
> the containers and algorithms.
>
> If you copy the appropriate flags from the Gears makefiles: the -
> I*stlport* and -D_STLP* lines, that should be sufficient to compile
> your app. You don't actually need to compile and of the .cc/.cpp files
> in STLport to get it working.
Which make file do I need to copy "-I*stlport* and -D_STLP*" from ?
And, I don't understand, if I only include head files of function
declares, how could it link to function implementions?

The vast majority of STL is just templates declarations. STLport is designed to allow you to use it using #include only and not having to compile or link any extra files. Think of it as inlining everything it needs, and the compiler/linker garbage collecting all the generated code it doesn't need. This isn't as bad for code size as it sounds.

In the Gears source tree, have a look at gears/tools/config.mk: specifically at the large "OS == android" section. There's a few STLport include directories and some (hacky) flags to define. Hopefully that should give you enough to get started.

Danny Brain

unread,
Jun 26, 2009, 9:40:03 PM6/26/09
to android-ndk
Did you end up getting this working? Can you post your Android.mk
file?

Thanks,
Danny.

On Jun 1, 1:05 pm, Richard Zhao <linux...@gmail.com> wrote:
> Hi John,
>
> Thank you very much. See my comments below.
>
>
>
> On Sat, May 30, 2009 at 10:29 PM, John Ripley <jrip...@google.com> wrote:
>
> > Hi Richard,
>
> > I'm the author of theSTLportmodifications in Gears. There's no
> > Android.mk because the way it's done is that you only have to add it
> > in your include path and set a few defines. This is deliberately to
> > avoid adding a lot to the binary size, but in hindsight I could have
> > arranged to built it as a library and then let the linker do garbage
> > collection. I've since managed to build it like this, but as there's
> > no real advantage to any application I have, I've not pursued it
> > further.
>
> > The only problems with usingSTLportas just include files are the
> > lack of iostreams, rtti and exceptions. However, rtti/exceptions is a
> > bigger problem than justSTLportas it needs a toolchain change, and
> > few libraries use iostreams anyway, so it was enough to just support
> > the containers and algorithms.
>
> > If you copy the appropriate flags from the Gears makefiles: the -
> > I*stlport* and -D_STLP* lines, that should be sufficient to compile
> > your app. You don't actually need to compile and of the .cc/.cpp files
> > inSTLportto get it working.
>
> Which make file do I need to copy "-I*stlport* and -D_STLP*" from ?
> And, I don't understand, if I only include head files of function
> declares, how could it link to function implementions?
>
> Thanks
> Richard
>
>
>
>
>
>
>
> > On May 21, 4:44 am, Richard Zhao <linux...@gmail.com> wrote:
> >> Hi All,
>
> >> I'm porting things to android. but android doesn't have stl support.
> >> Has anyone managed to usestlportin android?
>
> >>stlportin google gears said it have android support, but I didn't

Richard Zhao

unread,
Jun 27, 2009, 2:44:36 AM6/27/09
to andro...@googlegroups.com
Yes. Just add stlport to include path is OK. No android.mk.

Danny Brain

unread,
Jun 27, 2009, 2:53:04 AM6/27/09
to android-ndk
Sorry for the stupid question (I'm a bit new to C++), but how exactly
do I do that?
I tried adding a line something like:
LOCAL_CXXFLAGS := -Ipath/to/STLport/stlport -Ipath/to/STLport/stlport/
stl -Ipath/to/STLport/stlport/stl/config
to Android.mk as was described in the gears make file above, but this
did not give me any love. Resulting in the same old warning for
#include <memory>.

On Jun 27, 4:44 pm, Richard Zhao <linux...@gmail.com> wrote:
> Yes. Just add stlport to include path is OK. No android.mk.
>

Richard Zhao

unread,
Jun 27, 2009, 7:42:21 AM6/27/09
to andro...@googlegroups.com
I attached the stlport patch I created when I compiled my program.

Remember to add in Android.mk:
LOCAL_C_INCLUDES += /path/to/stlport/stlport

If you find any issues about the patch, please let me know.

Thanks
Richard
stlport-android.patch

Kumar

unread,
Jul 13, 2009, 2:06:47 AM7/13/09
to android-ndk
I was following this conversation, and thought If I could get any
reference/support around integrating the WebView component with
Gears.

Has anyone successfully integrated their App with Gears ? Any
suggestions on how to go about ?

Thank You,
Kumar

On Jun 27, 6:42 am, Richard Zhao <linux...@gmail.com> wrote:
> I attached the stlport patch I created when I compiled my program.
>
> Remember to add in Android.mk:
> LOCAL_C_INCLUDES += /path/to/stlport/stlport
>
> If you find any issues about the patch, please let me know.
>
> Thanks
> Richard
>
>  stlport-android.patch
> 5KViewDownload
Reply all
Reply to author
Forward
0 new messages