# Code with std::string fails to build on android

**URL:** <https://forums.unrealengine.com/t/code-with-std-string-fails-to-build-on-android/294063>\
**Category:** Mobile\
**Tags:** string, Mobile, unreal-engine, compile-error, Android, question, CPP\
**Created:** [September 19, 2014, 2:33am UTC](https://forums.unrealengine.com/t/code-with-std-string-fails-to-build-on-android/294063 "2014-09-19T02:33:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_56cfa58c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_56cfa58c](https://forums.unrealengine.com/u/anonymous_user_56cfa58c)\
**Post date:** [September 19, 2014, 2:33am UTC](https://forums.unrealengine.com/t/code-with-std-string-fails-to-build-on-android/294063/1 "2014-09-19T02:33:37Z")

</div>

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)

```

---

<div class="post-metadata">

**Author:** ![blurdot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blurdot](https://forums.unrealengine.com/u/blurdot)\
**Post date:** [September 19, 2014, 3:51pm UTC](https://forums.unrealengine.com/t/code-with-std-string-fails-to-build-on-android/294063/2 "2014-09-19T15:51:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Geremy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Geremy](https://forums.unrealengine.com/u/Geremy)\
**Post date:** [September 25, 2014, 7:11pm UTC](https://forums.unrealengine.com/t/code-with-std-string-fails-to-build-on-android/294063/3 "2014-09-25T19:11:02Z")

</div>

As far as I know, the STL _should_ work:

> **[Rocket and the STL](https://forums.unrealengine.com/questions/2695/rocket-and-the-stl.html)**
>
> In the documentation, under “Programming / Engine Programming / Unreal Container Structures,” is a list of container structures used with Rocket. https://rocket.unrealengine.com/docs/ue4/INT/Engine/Programming/Core/ContainerStructures/index.html A...

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.

---

<div class="post-metadata">

**Author:** ![Geremy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Geremy](https://forums.unrealengine.com/u/Geremy)\
**Post date:** [September 25, 2014, 7:20pm UTC](https://forums.unrealengine.com/t/code-with-std-string-fails-to-build-on-android/294063/4 "2014-09-25T19:20:53Z")

</div>

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

```
ANSI_TO_TCHAR
UTF8_TO_TCHAR
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_56cfa58c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_56cfa58c](https://forums.unrealengine.com/u/anonymous_user_56cfa58c)\
**Post date:** [October 13, 2014, 9:48pm UTC](https://forums.unrealengine.com/t/code-with-std-string-fails-to-build-on-android/294063/5 "2014-10-13T21:48:10Z")

</div>

Thanks, this helped a lot!
