简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM