Imath icon indicating copy to clipboard operation
Imath copied to clipboard

ImathMath std::hypot at android ndk r15b is not exist

Open mm-longcheng opened this issue 4 years ago • 11 comments
trafficstars

jni/../../../../src/Imath/src/Imath/ImathMath.h:106:40: error: no member named 'hypot' in namespace 'std'; did you mean simply 'hypot'? static T hypot (T x, T y) { return std::hypot (x, y); } ^~~~~~~~~~ hypot jni/../../../../src/Imath/src/Imath/ImathMath.h:106:14: note: 'hypot' declared here static T hypot (T x, T y) { return std::hypot (x, y); } use c api is correct. return hypot (x, y);

mm-longcheng avatar May 26 '21 06:05 mm-longcheng

Since C++, std::hypot should be available from #include <cmath>. Could you check the ndk r15b header to see if hypot is missing? Or if there is a preprocessor macro necessary to indicate c++11 support?

meshula avatar May 26 '21 21:05 meshula

APP_STL := gnustl_shared gnustl 4.9

#if __cplusplus >= 201103L
#ifdef _GLIBCXX_USE_C99_MATH_TR1

#undef hypot
#undef hypotf
#undef hypotl

  constexpr float
  hypot(float __x, float __y)
  { return __builtin_hypotf(__x, __y); }

  constexpr long double
  hypot(long double __x, long double __y)
  { return __builtin_hypotl(__x, __y); }

#endif // _GLIBCXX_USE_C99_MATH_TR1
#endif // C++11

APP_STL := c++_shared clang

#if _LIBCPP_STD_VER > 14
inline _LIBCPP_INLINE_VISIBILITY float       hypot(       float x,       float y,       float z ) { return sqrt(x*x + y*y + z*z); }
inline _LIBCPP_INLINE_VISIBILITY double      hypot(      double x,      double y,      double z ) { return sqrt(x*x + y*y + z*z); }
inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); }
#endif

gnustl_shared and not _GLIBCXX_USE_C99_MATH_TR1 hypot not find error. gnustl_shared and define _GLIBCXX_USE_C99_MATH_TR1 error: no member named 'acoshl' in the global namespace using ::acoshl; c++_shared can compile completely

gnustl_shared It seems that there is no way to compile by macro switch. clang c++ is not problem.

[arm64-v8a] gnustl_shared is not problem. arm64-v8a at ndk-r15b is port by clang c++. [armeabi-v7a] gnustl_shared will error. armeabi-v7a use the real gnustl 4.9.

Maybe simply change to using c api is a better choice

mm-longcheng avatar May 27 '21 02:05 mm-longcheng

Are you sure you are compiling for C++11?

lgritz avatar May 27 '21 02:05 lgritz

Android.mk

LOCAL_PATH := $(call my-dir)

MM_MAKE_HOME ?= $(MM_HOME)/mm-make

include $(CLEAR_VARS)

include $(LOCAL_PATH)/libImath_static.mk
include $(LOCAL_PATH)/libImath_shared.mk

Application.mk

APP_ABI := arm64-v8a armeabi-v7a # armeabi

APP_STL := gnustl_shared

APP_MODULES += libImath_static
APP_MODULES += libImath_shared

libImath_shared.mk

LOCAL_PATH := $(call my-dir)
LOCAL_MAKEFILE := $(this-makefile)
########################################################################
include $(CLEAR_VARS)  
########################################################################
LOCAL_MODULE := libImath_shared
LOCAL_MODULE_FILENAME := libImath_shared
########################################################################
LOCAL_CFLAGS += -fPIC
LOCAL_CFLAGS += -D__ANDROID__

LOCAL_CFLAGS += -Wall

LOCAL_CXXFLAGS += -std=c++11 
LOCAL_CXXFLAGS += -fexceptions
LOCAL_CXXFLAGS += -frtti 
########################################################################
LOCAL_LDLIBS += -fPIC
########################################################################
LOCAL_SHARED_LIBRARIES += 
########################################################################
LOCAL_STATIC_LIBRARIES += 
########################################################################
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../../src/Imath
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../include/android
########################################################################
LOCAL_SRC_FILES  += 
########################################################################
MY_SOURCES_PATH       := 
MY_SOURCES_FILTER_OUT := 
MY_SOURCES_EXTENSION  := 
#  
# config self source file path ,suffix.
MY_SOURCES_PATH += $(LOCAL_PATH)/../../../../src/Imath/src/Imath
MY_SOURCES_PATH += $(LOCAL_PATH)/android

# config filter out file and path.
# MY_SOURCES_FILTER_OUT += ../../filter-out-directory%
# MY_SOURCES_FILTER_OUT += ../../filter-out-source.c
MY_SOURCES_FILTER_OUT += ../../../../src/Imath/src/ImathTest%
MY_SOURCES_FILTER_OUT += ../../../../src/Imath/src/Imath/eLut.cpp
MY_SOURCES_FILTER_OUT += ../../../../src/Imath/src/Imath/toFloat.cpp

MY_SOURCES_EXTENSION += .cpp .c .cc .S
####
include $(MM_MAKE_HOME)/compile/definitions-sources.mk
include $(MM_MAKE_HOME)/compile/sources-rwildcard.mk
########################################################################
include $(BUILD_SHARED_LIBRARY)
########################################################################

definitions-sources.mk is part of my mk framework

rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))

sources-rwildcard.mk is part of my mk framework

# rwildcard
# get all source file.
SOURCES_PATH       := $(MY_SOURCES_PATH)
SOURCES_EXTENSION  := $(MY_SOURCES_EXTENSION)
SOURCES_FILTER_OUT := $(MY_SOURCES_FILTER_OUT)

SOURCES_PATTERNS   := $(foreach _ext,$(SOURCES_EXTENSION),%$(_ext))

SOURCE_FILES := $(foreach src_path,$(SOURCES_PATH), $(call rwildcard,$(src_path),*.*) ) 
SOURCE_FILES := $(SOURCE_FILES:/./%=%)
SOURCE_FILES  := $(filter $(SOURCES_PATTERNS),$(SOURCE_FILES)) 
SOURCE_FILES  := $(SOURCE_FILES:$(LOCAL_PATH)/%=%)
SOURCE_FILES  := $(filter-out $(SOURCES_FILTER_OUT),$(SOURCE_FILES)) 

LOCAL_SRC_FILES  += $(SOURCE_FILES)

# $(call ndk_log,$(LOCAL_MODULE).LOCAL_SRC_FILES: $(LOCAL_SRC_FILES))

LOCAL_CXXFLAGS += -std=c++11 i'm sure for C++11

mm-longcheng avatar May 27 '21 02:05 mm-longcheng

ndk-r15b target=android-21 math.h

#if __ISO_C_VISIBLE >= 1999
long double acoshl(long double);
#endif /* __ISO_C_VISIBLE >= 1999 */

[armeabi-v7a] The following configuration can compile correctly.

APP_STL := gnustl_shared
LOCAL_CXXFLAGS += -std=c++11 
LOCAL_CXXFLAGS += -D_GLIBCXX_USE_C99_MATH_TR1
target=android-21

upgrade android target >= android-21. or use APP_STL := c++_shared clang std.

mm-longcheng avatar May 27 '21 02:05 mm-longcheng

@mm-longcheng Does this mean the issue is resolved? Or is there a preprocessor definition that can be used to guard the hypot function to allow it to compile on older android targets?

meshula avatar May 30 '21 01:05 meshula

@mm-longcheng Does this mean the issue is resolved? Or is there a preprocessor definition that can be used to guard the hypot function to allow it to compile on older android targets?

return hypot (x, y);

Maybe it needs to be changed like this. If you don’t consider the type other than ‘float’ and 'double'.

mm-longcheng avatar May 31 '21 01:05 mm-longcheng

I believe that C hypot is specifically double.

lgritz avatar May 31 '21 01:05 lgritz

yes, C has hypotf for float

meshula avatar May 31 '21 04:05 meshula

    IMATH_HOSTDEVICE IMATH_DEPRECATED("use std::math functions")
    // static T hypot (T x, T y) { return std::hypot (x, y); }
    static T hypot (T x, T y) { return std::sqrt(x * x + y * y); }

sqrt for port it for template? It seems to fit the design better.

mm-longcheng avatar May 31 '21 04:05 mm-longcheng

That is not a correct implementation of hypot.

lgritz avatar May 31 '21 06:05 lgritz