Android NDK and STLPort

As you know, the Android NDK offers a way to run native code on Android platform, however the standard template library is not included in NDK.
While wandering on net looking for an easy solution to have my vector and my string in my native Android code without too much hassle, I have found a post which contained a link to STLPort library, configured to run with Android:

If you are looking only for using the containers and so from STL, not using iostream & company (which requires building the library itself), using this should be as easy as copying the header files in your project and start using it  as most of the functionalites come from template code which is contained in the header files.  So I have added the stlport folder with the header files to my project and tried to build the project with some STL testing code. However as soon as I start building it, I get this error:

obj/xxxx.o: In function `~vector':
[...]/native/stlport/stl/_alloc.h:213: undefined reference to `std::__node_alloc::_M_deallocate(void*, unsigned int)'

Checking the _alloc.h file we see there isthis comment:

// Default node allocator.
// With a reasonable compiler, this should be roughly as fast as the
// original STL class-specific allocators, but with less fragmentation.
// Define _STLP_USE_SIMPLE_NODE_ALLOC to use __new_alloc instead, which
// can be implemented without out-of-line functions.

Which probably means that by defining _STLP_USE_SIMPLE_NODE_ALLOC during the build probably will fix this issue. So I have added it to CFALGS, and seems like build is just fine, no more errors thrown.

More test need to be performed to see if everything is ok.

  1. The flag seems to be _STLP_USE_NEWALLOC now.

Leave a Comment