Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

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

    As you can see at https://developer.android.com/ndk/gu...p-support.html 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?

    #2
    We use gnustl_shared.

    Comment


      #3
      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?

      Comment


        #4
        There is an exception for gnustl_shared if the library is unchanged: http://gcc.gnu.org/onlinedocs/libstd...l/license.html

        Comment


          #5
          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.

          Comment


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

            Comment


              #7
              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_test[abi: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

              Comment


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

                Comment


                  #9
                  Originally posted by Chris Babcock View Post
                  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?

                  Comment


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

                    APP_STL := gnustl_shared

                    Comment


                      #11
                      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)

                      Comment


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

                        Comment


                          #13
                          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.
                          Last edited by darkZ; 06-11-2017, 12:27 PM.

                          Comment


                            #14
                            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.

                            Comment


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

                              Comment

                              Working...
                              X