Home » Android » NDK / Middleware / HAL » Android.mk variable to link system or external library during compilation

Android.mk variable to link system or external library during compilation

LOCAL_LDLIBS

This variable contains the list of additional linker flags for use in building your shared library or executable. It enables you to use the -l prefix to pass the name of specific system libraries. For example, the following example tells the linker to generate a module that links to /system/lib/libz.so at load time:

LOCAL_LDLIBS := -lz

Using this, LOCAL_LDLIBS variable you can also specify the path to the library, for example, your library libmylibrary.so resides in path /home/myuser/android/mylibrary/lib/libmylibrary.so, the you can use below code to link this library,

LOCAL_LDLIBS := -L/home/myuser/android/mylibrary/lib/

Example Android.mk might look like below,

$ vim Android.mk
include $(CLEAR_VARS)
LOCAL_LDLIBS += -llog -lz
LOCAL_STATIC_LIBRARIES := libavformat libavcodec libpostproc libswscale libavutil libx264 libswresample
LOCAL_C_INCLUDES += $(LOCAL_PATH)/ffmpeg
LOCAL_SRC_FILES := FFNewChunkedAudioVideoEncoder.c
LOCAL_CFLAGS := -march=armv7-a -mfloat-abi=softfp -mfpu=neon
LOCAL_MODULE := FFNewChunkedAudioVideoEncoder
include $(BUILD_SHARED_LIBRARY)

Reference – https://github.com/OpenWatch/ClientExperiments-Android/blob/master/jni/Android.mk

Reference : http://developer.android.com/ndk/guides/android_mk.html

Leave a Comment