Code with std::string fails to build on android

This code works just fine on Windows, but when I compile for android it fails to build.

This is the problem function.

FString ACashierController::StringFromBinaryArray(const TArray<uint8>& BinaryArray)
{
	std::string cstr(reinterpret_cast<const char*>(BinaryArray.GetData()), BinaryArray.Num());
	return FString(cstr.c_str());
}

And this is the build error I’m getting.

UnrealBuildTool: C:/Users//game/Source/game/CashierController.cpp:40: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, unsigned int, std::allocator<char> const&)'

UnrealBuildTool: C:/android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.8/include\ext/atomicity.h:83: error: undefined reference to '__gnu_cxx::__exchange_and_add(int volatile*, int)'

UnrealBuildTool: C:/android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.8/include\bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'

UnrealBuildTool: C:/android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.8/include\bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'

UnrealBuildTool: C:/Users//game/Source/game/LoginUI.cpp:129: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, unsigned int, std::allocator<char> const&)'

UnrealBuildTool: C:/android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.8/include\ext/atomicity.h:83: error: undefined reference to '__gnu_cxx::__exchange_and_add(int volatile*, int)'

UnrealBuildTool: C:/android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.8/include\bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'

UnrealBuildTool: C:/android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.8/include\bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'

UnrealBuildTool: C:/Users//game/Source/game/MainMenu.cpp:107: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, unsigned int, std::allocator<char> const&)'

UnrealBuildTool: C:/android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.8/include\ext/atomicity.h:83: error: undefined reference to '__gnu_cxx::__exchange_and_add(int volatile*, int)'

UnrealBuildTool: C:/android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.8/include\bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'

UnrealBuildTool: C:/android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.8/include\bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'

UnrealBuildTool: clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

I am also experiencing this issue. Is the STL only available for windows builds?

LogPlayLevel:Display: UnrealBuildTool: X:/NVPACK/android-ndk-r9c/sources/cxx-stl/gnu-libstdc++/4.8/include\bits/basic_ios.h:457: error: undefined reference to ‘std::ios_base::ios_base()’
LogPlayLevel:Display: UnrealBuildTool: X:/NVPACK/android-ndk-r9c/sources/cxx-stl/gnu-libstdc++/4.8/include/ostream:385: error: undefined reference to ‘std::basic_ios >::init(std::basic_streambuf >*)’
LogPlayLevel:Display: UnrealBuildTool: X:/NVPACK/android-ndk-r9c/sources/cxx-stl/gnu-libstdc++/4.8/include/streambuf:467: error: undefined reference to ‘std::locale::locale()’

Etc…

Can we use STL in our Unreal builds?
Are there limitations to which platforms allow for it and which do not?
Can we please get some insight here?

As far as I know, the STL should work:

However, I tend to stick to the Unreal templates, as they tend to work better within the context of UE4, work the same on each platform, easy to debug, etc.

For this particular case, you may want to take a look at FCString or the more specific FCStringAnsi and FCStringWide.

I forgot to mention, there are also these conversion macros:

ANSI_TO_TCHAR
UTF8_TO_TCHAR

Thanks, this helped a lot!