Search code examples
androidc++ndk-build

Forcing ndk-build to include C++ libraries


I have an application where all components are first assembled as static libraries and then those libraries are repacked to shared libraries. So the module(s) doing include $(BUILD_SHARED_LIBRARY) have empty LOCAL_SRC_FILES. With the way the components are laid out and composed, it makes sense and must remain that way.

However, the library for APP_STL only gets added if there is a C++ source (recognized by extension, which can be overridden with LOCAL_CPP_EXTENSION) in LOCAL_SRC_FILES. So the standard library does not get added and the final object does not link, because the component libraries do need it.

Is there a way to force NDK to include it?


Solution

  • There is an undocumented variable LOCAL_HAS_CPP that does it:

    LOCAL_HAS_CPP := true
    

    It is relatively new though. It is in the most recent NDK r16b (as of Mar 2018), but not in the r12b version we used until now.