1

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?

Jon
  • 1,381
  • 3
  • 16
  • 41

2 Answers2

2

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.

PerracoLabs
  • 16,449
  • 15
  • 74
  • 127
1

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.

TomTasche
  • 5,448
  • 7
  • 41
  • 67