Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ndk can't find atof function

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

But, when I try to load a library that contains calls to this function, I receive a runtime error:

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

I am a beginner in Android development using the NDK, so maybe I just missed something like flags, compiler directives, etc.

My android.mk file is:

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
like image 802
void Avatar asked Jan 28 '13 21:01

void


1 Answers

Google have moved some of the C standard library functions like atof() from being inline functions in header files to normal functions. The latest NDKs will default to building a .so that is only compatible with the latest Android devices that have the atof() function in the device's standard C library (libc.so). This means if you run a library on an older device that has an older version of the C library, you will get an error loading the dll as the expected atof() function will not exist.

Have you tried setting this in your Application.mk:

APP_PLATFORM := android-9

This will cause the ndk compiler to build code compatible with older Android versions.

You can also try downgrading your NDK installation to version 10b (this version predates the change where atof was moved from inline to part of libc so avoids the problem entirely).

like image 117
JosephH Avatar answered Sep 28 '22 21:09

JosephH