android 关于mk如何引用其它so库

 

https://blog.csdn.net/u011913612/article/details/72732177

 

https://blog.csdn.net/HTJOY1202/article/details/80777108

Android.mk

#jni/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := android-ffmpeg
LOCAL_SRC_FILES :=c ffmpeg-build/$(TARGET_ARCH_ABI)/libffmpeg.so
LOCAL_EXPORT_C_INCLUDES := ffmpeg-build/$(TARGET_ARCH_ABI)/include
LOCAL_ARM_NEON:=true
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE:=ffmpeg-jni
LOCAL_SRC_FILES:=ffmpeg-jni.cpp player.cpp fast_queue.cpp
LOCAL_LDLIBS:=-llog -lz -lm -landroid
LOCAL_SHARED_LIBRARIES:=android-ffmpeg
LOCAL_STATIC_LIBRARIES:=androidvideo androidaudio omxdecoder
include $(BUILD_SHARED_LIBRARY)

include $(call all-makefiles-under,$(LOCAL_PATH))
运行时,如果报错找不到so库,可以执行命令加载so所在路径:

export LD_LIBRARY_PATH=so_path
————————————————
版权声明:本文为CSDN博主「HTJOY1202」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/HTJOY1202/article/details/80777108

 

 

通常,开发android的软件,常常需要编译so库,然编译的这个so库,需要调用多个其它的so库。这里主要记录一下,编译so库时,调用其它so库的mk,是怎么写的。

这里讲的示例:需要编译出libtest3.so,它需要调用libtest1.so,libtest2.so

1. 在android 源码下编译


LOCAL_PATH:= $(call my-dir)
 
include $(CLEAR_VARS)
 
LOCAL_MODULE_TAGS := eng
 
LOCAL_SRC_FILES := \
    test3.cpp
 
LOCAL_C_INCLUDES += \
    $(LOCAL_PATH)/include/ \
    external/libpiccreader/
LOCAL_MODULE := libtest3
#LOCAL_LDLIBS += -lpthread -ldl
LOCAL_SHARED_LIBRARIES := liblog \
        libcutils \
        libutils \
        libtest1 \
        libtest2
include $(BUILD_SHARED_LIBRARY)
2. 在NDK的环境下编译

LOCAL_PATH:= $(call my-dir)
 
include $(CLEAR_VARS)
LOCAL_MODULE    := libtest1
LOCAL_SRC_FILES := libtest1.so
include $(PREBUILT_SHARED_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE    := libtest2
LOCAL_SRC_FILES := libtest2.so
include $(PREBUILT_SHARED_LIBRARY)
 
 
include $(CLEAR_VARS)
 
LOCAL_MODULE_TAGS := eng
 
LOCAL_SRC_FILES := \
    test3.cpp
 
LOCAL_MODULE := libtest3
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog 
LOCAL_SHARED_LIBRARIES := liblog \
        libcutils \
        libutils \
        libtest1 \
        libtest2
include $(BUILD_SHARED_LIBRARY)

ndk编译时如何指定所依赖库的路径

在Android.mk中添加

LOCAL_LDFLAGS += -L/path/to/lib -llibname

你可能感兴趣的:(ndk)