6

I am using std::round from C++ 11 on a Qt app built for android & iOS. But on android, I get the error that std::round is not a member of std in spite of including the cmath header.

How can I make std::round work on android ? Is there an alternative to std::round ?

Following is my android environment:

ANDROID_NDK_PLATFORM = android-23
NDK version          = r13b
ANDROID_NDK_TOOLCHAIN_VERSION = 4.9
101010
  • 41,839
  • 11
  • 94
  • 168
TheWaterProgrammer
  • 7,055
  • 12
  • 70
  • 159
  • This is https://github.com/android-ndk/ndk/issues/82, fyi. – Dan Albert Feb 26 '17 at 18:47
  • @DanAlbert Is there an upcoming release of NDK where these issues will be resolved ? – TheWaterProgrammer Feb 26 '17 at 19:07
  • 2
    As the bug says, it's scheduled for r15. In case tl;dr, it should be noted that this will never be fixed for gnustl, and will actually be "fixed" by making libc++ reliable enough that there will be no reason to use gnustl. – Dan Albert Feb 27 '17 at 21:17

2 Answers2

2

Looks like a few functions from the cmath header are missing from the Android-NDK, see here for more details.

It's very easy to implement your own round function however:

template<typename T>
T round(T v) {
  return int(v + 0.5);
}

Or check other suggestions/implementations here.

Community
  • 1
  • 1
101010
  • 41,839
  • 11
  • 94
  • 168
1

How can I make std::round work on android ?

(EDIT: updated instructions)

Switch to NDK r18 and remove the ANDROID_NDK_TOOLCHAIN_VERSION = 4.9 line since gcc is now completely removed from NDK, defaulting to clang.