davidv
davidv

Reputation: 383

Set ANDROID_STL in CMakeLists

I am compiling C++ library code in Android Studio 2.2. I follow the new guide, where I add all the files to my project and compile it using CMake (and CMakeLists.txt) like this. I want to use C++14 features, and stuff like atomic, stoi etc. but the building is failing with errors.

error: no type named 'condition_variable' in namespace 'std'
error: no member named 'stoi' in namespace 'std'

This is what my CMakeLists looks like (other lines set source files and other stuff):

find_library(GLES GLESv2)
include_directories(${COMMON_PATH} /usr/local/include)
set(ANDROID_STL "c++_shared")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -latomic")

add_library(native-lib SHARED ${COMMON_SRC})
target_link_libraries(native-lib ${GLES})

I found this article on the android page (here), but I don't know how and if I can do this when using CMakeLists and not ndk-build. I see other question that solve it using the c++_static runtime but only with ndk-build.

Upvotes: 6

Views: 10121

Answers (2)

Gerry
Gerry

Reputation: 1233

  • This documentation would be more useful for cmake case: arguments "-DANDROID_STL=c++_shared
  • Gradle also packs libc++_shared.so into APK when using c++_shared; bypassing Gradle might cause trouble for your app on early version of Android OS.

at the time of this question, Android Studio might have trouble; at the time now Android Studio 3.1.3, it should be ok

Upvotes: 6

goe
goe

Reputation: 2303

The cross-compilation process used to generate the native libraries for Android uses the c++ dependencies from the NDK libraries. The NDK provided by Google is good and it has lots of things, but the C++11 and C++14 support is not complete.

If you want to use C++14 features, you can use other NDK like CrystaX NDK for example. With CrystaX you have also C++17 support.

Upvotes: 0

Related Questions