android NDK编译中遇到atof错误

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

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

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

http://stackoverflow.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中了,不会报找不到符号的错误;

你可能感兴趣的:(android)