cannot locate symbol "atof" referenced by错误分析

时间:2020-11-28 04:24:30

ndk从r8升级到r10后, 使用eclipse编译出来的so库报错了,加载库的时候报错cannot locate symbol "atof" referenced by

原因:Android的stdlib.h中atof是内联的
解决方法:将所有的atof改成strtod
示例代码:
char *strpi = "3.1415";
double dpi;
dpi = atof(strpi); 修改为: dpi = strtod(strpi, NULL);

参考自:http://*.com/questions/14571399/Android-ndk-cant-find-atof-function
原文如下:
From stdlib.h in the Android source;
static __inline__ double atof(const char *nptr)
{
return (strtod(nptr, NULL));
}
atof is in other words not a library function, it's an inline function that calls strtod.
If you need to call through loading a library, just use strtod instead.

2、
在Appication.mk里第一行加入 APP_PLATFORM := android-19 (我的就是这个问题),不行的话再试试 改成 APP_PLATFORM := android-9
再不行就多换几个ndk版本试试这个方法。

3、
今天使用ndk编译一个第三方库,编译ok后,运行的时候报错

dlopen failed:cannot locate symol "atof" referenced by ...

网上查找了资料,原因是atof不是库中的函数,而是inline函数:

http://*.com/questions/14571399/Android-ndk-cant-find-atof-function

解决思路是制作一个静态库,作为一个中间体,然后再根据这个静态库生成最终的动态库;

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := YourLibStatic
LOCAL_SRC_FILES := xxx.c
# for logging
LOCAL_LDLIBS += -llog
# for native windows
LOCAL_LDLIBS += -landroid

LOCAL_CFLAGS += -UNDEBUG

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := YourLib
LOCAL_STATIC_LIBRARIES :=YourLibStatic

include $(BUILD_SHARED_LIBRARY)

上面的YourLibStatic就是一个中间体,而YourLib是你最终想要产生的东西;

经过这么一转换,atof自然就包含到so中了,不会报找不到符号的错误;

要么就换成r8编译。