2

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)
nmxprime
  • 1,506
  • 3
  • 25
  • 52
  • 1
    You get the error because those libraries are not linked. Probably NDK can't find those libraries when compiling. You need to create modules for those libraries and link to those modules. Instead of using BUILD_SHARED_LIBRARY, use PREBUILT_STATIC_LIBRARY when building your modules for static libraries. – eozgonul Jan 27 '14 at 14:10
  • From ndk docs, PREBUILT_STATIC_LIBRARY is the same as PREBUILT_SHARED_LIBRARY, which requires the value of LOCAL_SRC_FILES must be a single path to a prebuilt shared library, which means i cannot specify multiple static libraries to PREBUILT_SHARED_LIBRARY ?? – nmxprime Jan 27 '14 at 14:20
  • 1
    Creating multiple modules, in this case 4, should solve that "single path to a prebuilt library" problem. Create modules for each of libavutil, libavcodec, libswscale and libx264 and then link them in your main module. – eozgonul Jan 27 '14 at 14:32

1 Answers1

3

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.

nmxprime
  • 1,506
  • 3
  • 25
  • 52
Digit
  • 2,073
  • 1
  • 13
  • 10
  • Thanks,, that solved by the comments by user2359247. However accepting this, because someone in future may find it useful! – nmxprime Feb 03 '14 at 03:59