Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::round is not a member of std on android

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
like image 650
TheWaterProgrammer Avatar asked Feb 25 '17 18:02

TheWaterProgrammer


2 Answers

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.

like image 81
101010 Avatar answered Nov 09 '22 23:11

101010


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.

like image 28
Bruno Alexandre Rosa Avatar answered Nov 09 '22 23:11

Bruno Alexandre Rosa