Android ndk cannot find atof function

I am trying to use the open source C library in my Android project. This library uses the atof() . I know that atof() is a function defined in the C standard library (stdlib.h). Therefore, it must be implemented in the standard C library on Android NDK (bionic library).

But when I try to load a library containing calls to this function, I get a runtime error:

 java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1285]: 86 cannot locate 'atof'.... 

I'm starting Android development with the NDK, so maybe I just missed something like flags, compiler directives, etc.

My android.mk file:

 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_ALLOW_UNDEFINED_SYMBOLS := true LS_CPP=$(subst $(1)/,,$(wildcard $(1)/$(2)/*.c)) LOCAL_MODULE := libA LOCAL_SHARED_LIBRARIES := \ libgmodule-2.0 \ libgobject-2.0 \ libgthread-2.0 \ libglib-2.0 LOCAL_SRC_FILES:= sourceFile.c include $(BUILD_SHARED_LIBRARY 
+7
android android-ndk
source share
2 answers

From stdlib.h in the Android source ;

 static __inline__ double atof(const char *nptr) { return (strtod(nptr, NULL)); } 

atof In other words, this is not a library function, it is a built-in function that calls strtod .

If you need to call through the library download, just use strtod instead.

+1
source share

Google has moved some of the standard C library functions, such as atof (), from built-in functions to header files for regular functions. Recent NDKs will by default create .so, which is only compatible with the latest Android devices that have the atof () function in the deviceโ€™s standard C library (libc.so). This means that if you run the library on an older device that has an older version of the C library, you will get an error loading the dll, since the expected atof () function will not exist.

You tried to install this in your Application.mk application:

 APP_PLATFORM := android-9 

This will force the ndk compiler to create code compatible with older versions of Android.

You can also try downgrading the NDK installation to version 10b (this version precedes the change when atof was moved from the built-in libc part to avoid the problem completely).

+4
source share

All Articles