How can we set the C++ runtime that gets used by Android NDK?

As you can see at C++ library support  |  Android NDK  |  Android Developers Android NDK offers the choice between a wide range of C++ runtimes.

It seems like by default UE4 chooses stlport. Unfortunately stlport does not support the C++11 features of the stdlib. So to be able to link against 3rd party libraries that use C++ 11 stdlib features we need to choose the LLVM libc++ runtime.

How can we do that with UE4?

We use gnustl_shared.

Interestingly is has worked back when our 3rd party lib wasn’t using C++ 11 stdlib features and was using stlport.

However gnustl is licensed under the GPLv3, so doesn’t UE4 using a GPLv3 standardlib force all your customers to release their games under the GPLv3 themselves?

There is an exception for gnustl_shared if the library is unchanged: http://gcc.gnu.org/onlinedocs/libstdc++/manual/license.html

Sorry to bring this thread back to life, but does c++11 work out of the box now for Android NDK?

I am trying to link a pre-built library file which uses c++11 features, but I am getting linking errors when building the actual game project.

UE4 uses -std=c++14. I believe this was done in 4.15.

I created a simple external library with no c++11 code and I am able to link that in correctly to an Android project.
However, as soon as I add in some c++11 code, even some std::string related code, the linking fails giving me errors which curiously look like a c++11 related problem

This is what I get as soon as I include a function returning std::string in the external library.

libbiksolver.a(BIK_DataTypes.cpp.obj):BIK_DataTypes.cpp:function bik_test::string_testabi:cxx11: error: undefined reference to ‘std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)’

Thanks for your help!

Best,
darkZ

Did you include the right STL? gnustl_shared should be used.

I see, it seems like I did not. Can your provide some help as to how to use gnustl_shared in this context?

The external library when compiled needs to use gnustl_shared in application.mk:

APP_STL := gnustl_shared

Oh, I remember the sleepless nights when trying to make 3rd party static libraries work… To make it work all of my projects have Application.mk with such settings:

APP_STL := gnustl_static
APP_ABI := armeabi-v7a
APP_CXXFLAGS := -std=c++11

(I’m using mostly 4.14 now, for newer version you can change std to c++14, I think)

Yeah, using static is fine unless you need the interfaces public. And yes, we’ve moved to c++14 now.

The latest version of Android Studio seems to support CMake builds instead of ndk builds hence I can’t seem to use the Application.mk file. Should I be using an older version for this?

Basically the issue I am facing is that I am not able to create a static library using the CMake build system by specifying STATIC keyword in the add_library command. It only wants to create shared libraries.

EDIT
Nevermind, I was able to generate a static library now. Thanks.

darkZ, can you please elaborate how did you do that? Where is Application.mk file? Or where should it be created? Any documentation links or explanation how should c++11 compilation be enabled for Android packaging will be much appreciated.
P.S.
I am trying to package “game” in UE4.16.2 with elements of c++11 in the code, and so far it seems to be no way at all. Please prove me wrong.

Is it possible to use libc++ instead of gnustl??

Bump.

GCC has been deprecated since r11 (released March 2016).

As of r18 (https://developer.android.com/ndk/do…vision_history) GCC and gnustl have been removed.

Is there a timetable for switching Unreal Android builds to linking against libc++_shared or libc++_static instead of libgnustl_shared?

Any update about linking libc++ instead of libgnustl?

It would be great to know if this is in the works or what steps we can take to modify the engine to make this work for us.

Any updates on this one? This issue prevents from using third-party c++ libraries.

This may help some of you: https://dawnarc.com/2019/07/ue4andro…member-of-std/

I have an issue (https://answers.unrealengine.com/que…or-dlopen.html) that seems to be related to UE4’s lack of libc++ support.