Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NDK eabi - how to make ndk know to use hard fp?

I've prebuilt library (libxxx.so) with "-mfloat-abi=hard" parameter. Now i'd like to compile my native code with this lib and build shared lib (.so) with ndk.

Application.mk:

APP_ABI := armeabi-v7a

Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := xxx

LOCAL_SRC_FILES := libxxx.so

include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS) LOCAL_MODULE := xxx_wrapper

LOCAL_SRC_FILES := xxx_wrapper.cpp xxx_wrapper.h

LOCAL_SHARED_LIBRARIES := xxx

LOCAL_C_INCLUDES := /softdev/host/include/

LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog

LOCAL_ARM_NEON := true

LOCAL_CXXFLAGS += -mfpu=vfp -mfloat-abi=hard

LOCAL_CFLAGS += -mfpu=vfp -mfloat-abi=hard

include $(BUILD_SHARED_LIBRARY)

on ndk-build i'm getting an error:

/softdev/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: /Users/asmirnov/Documents/dev/src/project/obj/local/armeabi-v7a/objs-debug/xxx_wrapper/xxx_wrapper.o uses VFP register arguments, output does not /softdev/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: /Users/asmirnov/Documents/dev/src/project/obj/local/armeabi-v7a/libxxx.so uses VFP register arguments, output does not collect2: ld returned 1 exit status

How can i fix it? Both .o files are hard-float according to output and i can't figure out what "output" means? I've added '-mfpu=vfp -mfloat-abi=hard' to my module description.

UPDATE: i've executed ndk-build V=1 and found no "-mfpu=vfp -mfloat-abi=hard" arguments in command-line, so i i've tried to do it manually (but still no result):

mba-anton:build asmirnov$ /softdev/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++

-Wl,-soname,libxxx_wrapper.so -shared --sysroot=/softdev/android-ndk-r8e/platforms/android-8/arch-arm /Users/asmirnov/Documents/dev/src/xxx_jni/obj/local/armeabi-v7a/objs-debug/xxx_wrapper/xxx_wrapper.o /Users/asmirnov/Documents/dev/src/xxx_jni/obj/local/armeabi-v7a/libstdc++.a -lgcc /Users/asmirnov/Documents/dev/src/xxx_jni/obj/local/armeabi-v7a/libxxx.so -no-canonical-prefixes -march=armv7-a -mfpu=vfp -mfloat-abi=hard -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -L/softdev/android-ndk-r8e/platforms/android-8/arch-arm/usr/lib -L/usr/lib -llog -lstdc++ -lc -lm -o /Users/asmirnov/Documents/dev/src/xxx_jni/obj/local/armeabi-v7a/libxxx_wrapper.so /softdev/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: /Users/asmirnov/Documents/dev/src/xxx_jni/obj/local/armeabi-v7a/objs-debug/xxx_wrapper/xxx_wrapper.o uses VFP register arguments, output does not /softdev/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: /Users/asmirnov/Documents/dev/src/xxx_jni/obj/local/armeabi-v7a/libxxx.so uses VFP register arguments, output does not collect2: ld returned 1 exit status

like image 836
4ntoine Avatar asked Nov 01 '22 13:11

4ntoine


2 Answers

You may want this: -march=armv7-a -mfloat-abi=softfp -mfpu=vfp

In a word, "-mfloat-abi=hard" or "-mfloat-abi=softfp" argument does not refers to use hardware or software FPU.

Please see Getting hardware floating point with android NDK for more details, fadden has given a great and clear answer, so I won't bother to repeat it here.

like image 194
Ludy Su Avatar answered Nov 09 '22 03:11

Ludy Su


Solution:

APP_ABI := armeabi-v7a-hard

instead of

APP_ABI := armeabi-v7a

Also you can add these flags in Android.mk:

LOCAL_CXXFLAGS  := -O2 -mfpu=vfpv3-d16 -mhard-float -D_NDK_MATH_NO_SOFTFP=1 -march=armv7-a -mfloat-abi=hard
LOCAL_CFLAGS    := -O2 -mfpu=vfpv3-d16 -mhard-float -D_NDK_MATH_NO_SOFTFP=1 -march=armv7-a -mfloat-abi=hard
LOCAL_LDFLAGS   := -lm_hard
like image 37
minyor Avatar answered Nov 09 '22 03:11

minyor