Jon
Jon

Reputation: 1499

Enabling C++17 on Android using latest NDK (r18)

From here (https://developer.android.com/ndk/guides/cpp-support), it looks like Android NDK r18 provided support for C++17. The examples though on the page only show how to enable it for the ndk build script approach. My project is using CMake.

I tried the approach outlined here which is not android specific (How to enable C++17 in CMake) but I was getting compilation errors indicating that my compiler is unable to set the standard to 17.

Is anyone aware on how to do this?

Upvotes: 1

Views: 2680

Answers (2)

TomTasche
TomTasche

Reputation: 5526

In your CMakeLists.txt you can specify the C++ standard being used:

set(CMAKE_CXX_STANDARD 17)

Note: this only works in the "first" CMakeLists.txt! If you are including other CMakeLists.txt from yours Android Studio won't use C++17.

Upvotes: 1

Perraco
Perraco

Reputation: 17360

Include the "-std=c++17" flag to CMAKE_CXX_FLAGS_DEBUG and CMAKE_CXX_FLAGS_RELEASE, as next:

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -O0 -std=c++17 -fexceptions")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -std=c++17 -fexceptions -DNDEBUG")

Take into account that the rest of flags are just for the example and will differ depending on what you need.

Upvotes: 2

Related Questions