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

Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home JAVA Programs Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply