C++11 cmath functions not in std namespace for android NDK w/gcc-4.8 or clang 3.4

后端 未结 2 674
情歌与酒
情歌与酒 2021-02-19 13:15

After C++11, various cmath functions previously in the global namespace are moved to the std namespace, when including the h

相关标签:
2条回答
  • 2021-02-19 14:16

    If functions are really missing, you have to write them yourself (or copy them from some other implementation).

    In the Android NDK, some functions seem to be there, but just outside of namespace std. I have worked around the same issue for the round function by adding a function round to namespace std, which just falls back on the round function from the global scope.

    namespace std
    {
        inline int round(float x)
        {
            return ::round(x);
        }
    }
    

    If you want to use this in a portable way, you would have to protect this with preprocessor macros.

    0 讨论(0)
  • 2021-02-19 14:17

    This seems to be a known issue with C++11 support on android. There is a known issue that indicates that a lot of the routines are missing:

    When compiling c++ code with -std=c++11 and using gnustl_shared, many C99 math functions are not provided by the <cmath> header as they should.

    You're probably better off assuming that only a limited subset of the c++ library is available for android - this seems to be indicated in the CPLUSPLUS-SUPPORT.html file in the docs/ for the ndk.

    Mind you when I have:

    APP_STL := c++_static
    

    in my Application.mk and

    LOCAL_CPPFLAGS  := -std=c++11
    

    in my Android.mk, then files making use of std::cbrt and std::round compile cleanly; but it is against the static LLVM libc++, rather than against the gnu standard library.

    0 讨论(0)
提交回复
热议问题