Reputation:
I am attempting to compile an Android-9 project that calls Android NDK functions (such as "AAsset_close") by running "ndk-build" via the Cygwin terminal, but the "ndk-build" command returns an error message, stating that it is unable to find the function definitions.
The error messages from "ndk-build" are as follows:
[Android NDK path]/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: [project folder]/static library: in function [function name]:[file name]:39: error: undefined reference to 'AAsset_close'
etc.
My "Android.mk" file is as follows:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := <name of project>
LOCAL_C_INCLUDES := <folders where header files are located>
LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__ -DtyANDROID
LOCAL_CPPFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__ -DtyANDROID
LOCAL_LDLIBS := -lm -lEGL -lGLESv2 -llog -lz -landroid
LOCAL_STATIC_LIBRARIES := android_native_app_glue
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES := <source files>
include $(BUILD_STATIC_LIBRARY)
...
My "Application.mk" makefile is as follows:
APP_ABI := armeabi armeabi-v7a x86
APP_PLATFORM := android-9
According to the "nm" Unix command, this function is defined within the Android NDK library "libandroid.so", which is present in the NDK path for all target platforms. As demonstrated above, I have included "-landroid" to the "LOCAL_LDLIBS" macro, which should allow me to link against that library. What else do I need to do to fix this compile error?
Upvotes: 0
Views: 1271
Reputation: 57203
You show the Android.mk
that builds a static library, at this step the linker is not called, threfore $(LOCAL_LDLIBS)
is ignored. You probably have another Android.mk
or a different section, where you have
include $(BUILD_SHARED_LIBRARY)
Please check, -landroid
is probably missing in that section.
Upvotes: 3