Android NDK Error: ‘std::string’ has not been declared

Recently using NDK, add to the C++ header file
#include <string>

After ndk-build, I got an error
x.h: fatal error: string: No such file or directory

Try replacing it with
#include <string.h>
The error continues after ndk-build
x.h: error: ‘std::string’ has not been declared

I was really depressed, then I searched the internet, and it turns out that I need to make Android NDK support STL
Import STL libraries to the Android NDK code
> This is a quick tip for those who are beginning to write native Android code.
> As one may have noticed, it isn’t possible to use containers like, string, vector, list inside the NDK samples.
> These are all part of the STL (Standard Template Library), and are expected to be available when writing C++ code.
> The Application.mk, works similarly as the Android manifest file for your NDK code,
> allowing the programmer to add permissions and define other applications’ properties, like such as ‘enabling’ the STL support.

Place the Application.mk in the jni directory (the content is as follows)
APP_STL := stlport_static

Similar Posts: