Question

i have 4 static libraries libavcodec.a libavutil.a libswscale.a libx264.a

I want to link it with libmytest.so

I tried below Android.mk script

LOCAL_PATH := $(call my-dir)
INITIAL_PATH := $(LOCAL_PATH)

include $(CLEAR_VARS)
LOCAL_MODULE := mytest

LOCAL_SRC_FILES := mytest.c

LOCAL_LDLIBS += -llog
LOCAL_WHOLE_STATIC_LIBRARIES := libavutil libavcodec libswscale libx264

include $(BUILD_SHARED_LIBRARY)

mytest.c calls many functions from those libraries. The 4 libraries are placed inside PROJECTPATH\jni\.

But i get undefined reference to all functions from those libraries.

I tried giving LOCAL_ALLOW_UNDEFINED_SYMBOLS := truewhich allowed me to create shared library, but when i launch the app, i get

01-22 07:15:15.650: E/AndroidRuntime(9655): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1285]:  1868 cannot locate 'avcodec_register_all'...
01-22 07:15:15.650: E/AndroidRuntime(9655):     at java.lang.Runtime.loadLibrary(Runtime.java:370)
01-22 07:15:15.650: E/AndroidRuntime(9655):     at java.lang.System.loadLibrary(System.java:535)
Was it helpful?

Solution

You need to define a PREBUILT_STATIC_LIBRARY for each one of your libraries if you do not build them from source, e.g.

include $(CLEAR_VARS)
LOCAL_MODULE := avutil
LOCAL_SRC_FILES := $(LOCAL_PATH)/jni/libavutil.a
include $(PREBUILT_STATIC_LIBRARY)

... [repeat for other prebuilt libraries].

LOCAL_STATIC_LIBRARIES only understands module names, i.e. names of stuff that have been declared through their own ndk-build module definition. I'm surprised it didn't provide a warning about missing modules though, but it's the most likely explanation corresponding to your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top