How to Fix a Error in Building Boost Library for Android Framework in Linux

When I first tried building the Boost 1.53.0 library for Android using the NDK on my Linux machine, I hit a strange error. Everything was working fine until I got to compiling libraries like regex, thread, wave, and graph. That’s when this message popped up:

./boost/functional/hash/extensions.hpp:269: error: no matching function for call to 'hash_value(const wchar_t&)'

At first, this was frustrating because all the other Boost modules built without issues. I’ll walk you through the code setup, why this error happens, how I fixed it, and finally share a small test project I built to verify the solution.

My Initial Setup

Here’s the exact user-config.jam file I was using:

import os ;

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

androidNDKRoot = ../android-ndk-r8e ;

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-9/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++/4.4.3/include
    <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/include
    <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.4.3/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
  ;

And I was running builds like this:

./b2 --with-regex  toolset=gcc-android4.4.3 link=static runtime-link=static target-os=linux --stagedir=android
./b2 --with-thread toolset=gcc-android4.4.3 link=static runtime-link=static target-os=linux --stagedir=android
./b2 --with-graph  toolset=gcc-android4.4.3 link=static runtime-link=static target-os=linux --stagedir=android

Why The Error Happened

The root of the problem lies in how Boost handles wchar_t and std::wstring.

  • The flag -DBOOST_NO_INTRINSIC_WCHAR_T told Boost not to assume wchar_t was a native type.
  • The older GNU libstdc++ bundled with Android NDK r8e didn’t fully support std::wstring the way Boost expected.
  • So when Boost tried to instantiate hash_value(const wchar_t&) (used in hashing std::wstring), it couldn’t find a valid overload → build failure.

Essentially, Boost was expecting something that my toolchain didn’t provide.

The Fix I Applied

The solution was simple but effective: I disabled Boost’s use of std::wstring altogether by adding this compile flag:

<compileflags>-DBOOST_NO_STD_WSTRING

Now my using gcc section looked like this:

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-9/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++/4.4.3/include
    <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/include
    <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi/include
    <compileflags>-D__GLIBC__
    <compileflags>-DBOOST_NO_INTRINSIC_WCHAR_T
    <compileflags>-DBOOST_NO_STD_WSTRING     #  the important fix
    <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
  ;

After this change, all my Boost libraries compiled successfully.

Testing The Fix With a Small Project

I didn’t just want to stop at “it builds now.” I also wanted to prove that the compiled Boost libraries worked on Android. So I wrote a small sample.

hello_boost.cpp

#include <boost/thread.hpp>
#include <boost/regex.hpp>
#include <iostream>
#include <string>

void worker() {
    std::cout << "Thread says hi!\n";
}

int main() {
    const std::string text = "abc123";
    const boost::regex r("[a-z]+\\d+");

    std::cout << "Regex match? " << std::boolalpha
              << boost::regex_match(text, r) << "\n";

    boost::thread t(worker);
    t.join();

    std::cout << "All good.\n";
    return 0;
}

Jamroot

import project ;

project : requirements
  <include>.
  <library-path>android/lib
  <link>static
  ;

exe hello_boost
  : hello_boost.cpp
  : <find-library>boost_thread
    <find-library>boost_regex
    <find-library>boost_system
  ;

Build Script (build_all.sh)

#!/usr/bin/env bash
set -euo pipefail

# Build and stage Boost
./b2 --with-regex --with-thread --with-system \
    toolset=gcc-android4.4.3 link=static runtime-link=static target-os=linux \
    --stagedir=android -j$(nproc)

# Build the test program
./b2 toolset=gcc-android4.4.3 link=static runtime-link=static -j$(nproc)
echo " Done. Check bin.v2 for hello_boost ARM binary."

Quick Troubleshooting Notes

  • If the error still appears, check that -DBOOST_NO_STD_WSTRING is actually passed to the compiler.
  • If linking fails, confirm Boost libraries are staged under ./android/lib.
  • Don’t mix gnustl, stlport, and libc++—pick one and stick with it.
  • Match your ABI (armeabi, armeabi-v7a, etc.) across Boost and your Android project.

Final Thought

This was one of those classic “small flag, big headache” situations. By simply defining BOOST_NO_STD_WSTRING, I bypassed Boost’s problematic wchar_t handling in the old Android NDK environment. When building Boost for Android, especially with older NDKs, pay close attention to STL support and compiler macros. It can save hours of chasing cryptic template errors. With this fix, I was able to build regex, thread, and graph successfully, and my sample app ran without issues. Hopefully, this walkthrough saves you the same headache I went through.

Related blog posts