问题
I am running into problems when compiling a small Java program that uses several custom c++ libraries. All the libraries are targeting armeabi-v7a and are compiled with hard-float support (mfloat-abi=hard -mfpu=neon -mhard-float -D_NDK_MATH_NO_SOFTFP=1). I have couple of other cpp files that are part of the Java/Android project; those are also compiled with the above settings and I link against libm_hard.a (instead of libm.a)
When I run the program, I am getting strange behavior with floats from the cpp files (not custom libraries), similar to arm cortex a9 cross compiling strange floating point behaviour. Legitimate float values (in the code, checked via the debugger) are printed on stdout or fstream as extremely small values (e.g. 1.47895e-309).
std::ofstream os;
os.open(filename, std::ios::out);
double x = 0.34343;
double y = log(0.1);
os << x << "\t" << y << endl;
os.close();
It seems like this happens because libc++ library is not compiled for hard-float; I tried both static and shared version of libc++, and I get the same behavior. I also checked them via readelf and it appears that they are not compiled for hard-float (no mention of VPF registers). I was not able to find a version of libc++ (static nor shared) that's compiled for hard-float in the NDK.
- Android SDK: 21 (tried with 23 as well)
- NDK: 14.1.3816874
- Android Studio: 2.3.1
I can't (easily) change the upstream libraries from hard-float to softfp; some are focused on heavy matrix processing and optimized for hard-float. And, from what I understand, I cannot mix softfp and hard...
Beyond recompiling libc++ for hard-float, do I have any other options? (I understand a while back Google dropped support for hard abi, which must have had corresponding libc++ library)
EDIT: added example code
回答1:
The hard float ABI support was removed from the NDK in r12: https://android.googlesource.com/platform/ndk/+/master/docs/HardFloatAbi.md
Stop using libm_hard and you should be fine (not removing this was an oversight that is fixed in r15, sorry for the confusion!).
It's really important to note that the non-hard-float-ABI still uses floating point instructions. The only difference is the function argument passing ABI.
来源:https://stackoverflow.com/questions/43445539/android-ndk-libc-support-for-hard-float