title: FFMpeg on Android, undefined references to libavcodec functions, although it is listed on command line
body: <p>I have a problem with unresolved references to ffmpeg's libavcodec functions, so far failed to find the answer in other places (including my mind) :) </p>
  
  <p>Let me describe my setup - it takes space, but is really basic, it might be that I'm failing to see some error...</p>
  
  <p>I built an FFMPeg with ndk r5 toolchain, ffmpeg port I got from <a href="http://bambuser.com/opensource" rel="nofollow noreferrer">http://bambuser.com/opensource</a> (as recommended in other questions here). It built fine, so I put several static libraries in my project like this:</p>
  
  <pre><code>&lt;project&gt;/jni/bambuser_ffmpeg/libavcodec.a
  &lt;project&gt;/jni/bambuser_ffmpeg/libavformat.a
  &lt;project&gt;/jni/bambuser_ffmpeg/libavcore.a
  &lt;project&gt;/jni/bambuser_ffmpeg/libavutil.a
  </code></pre>
  
  <p>Next, I created an Android.mk in bambuser_ffmpeg folder to list these libs as a prebuilt ones:</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  
  include $(CLEAR_VARS)
  LOCAL_MODULE := bambuser-libavcore
  LOCAL_SRC_FILES := libavcore.a
  include $(PREBUILT_STATIC_LIBRARY)
  
  include $(CLEAR_VARS)
  LOCAL_MODULE := bambuser-libavformat
  LOCAL_SRC_FILES := libavformat.a
  include $(PREBUILT_STATIC_LIBRARY)
  
  (same for other two libs)
  </code></pre>
  
  <p>Next, I have another module which references these libs in its Android.mk, sets up include paths, etc:</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  
  include $(CLEAR_VARS)
  
  LOCAL_MODULE := ffmpegtest
  LOCAL_STATIC_LIBRARIES := bambuser-libavcodec bambuser-libavcore bambuser-libavformat bambuser-libavutil
  LOCAL_SRC_FILES := ffmpeg_test.cpp
  LOCAL_C_INCLUDES := $(LOCAL_PATH)/../bambuser_ffmpeg/include
  LOCAL_LDLIBS    := -llog -lz
  
  include $(BUILD_SHARED_LIBRARY)
  </code></pre>
  
  <p>And finally I have my ffmpeg_test.cpp which is really basic, like this:</p>
  
  <pre><code>#include &lt;jni.h&gt;
  
  extern "C" {
  #include &lt;libavcodec/avcodec.h&gt;
  #include &lt;libavformat/avformat.h&gt;
  }
  
  extern "C" {
      JNIEXPORT jint JNICALL Java_com_the7art_ffmpegtest_PaintThread_testFFMpeg(JNIEnv* env, jobject obj, jstring fileName);
  }
  
  JNIEXPORT jint JNICALL Java_com_the7art_ffmpegtest_PaintThread_testFFMpeg(JNIEnv* env, jobject obj, jstring fileName)
  {
      av_register_all();
      return 0;
  }
  </code></pre>
  
  <p>When I run <em>ndk-build</em>, it compiles fine, but when linking it prints an unresolved reference to almost every function in <em>libavcodec</em>. Looks like only this lib's functions are failing to be located:</p>
  
  <pre><code>/home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(allformats.o): In function `av_register_all':
  /home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/allformats.c:47: undefined reference to `avcodec_register_all'
  /home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(utils.o): In function `parse_frame_rate':
  /home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:3240: undefined reference to `av_parse_video_rate'
  /home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(utils.o): In function `parse_image_size':
  /home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:3234: undefined reference to `av_parse_video_size'
  /home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(utils.o): In function `flush_packet_queue':
  /home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:1277: undefined reference to `av_free_packet'
  /home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:1283: undefined reference to `av_free_packet'
  /home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(utils.o): In function `get_audio_frame_size':
  /home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:766: undefined reference to `av_get_bits_per_sample'
  /home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(utils.o): In function `ff_interleave_add_packet':
  /home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:2909: undefined reference to `av_dup_packet'
  and so on...
  </code></pre>
  
  <p>I fail to figure why this is happening. I tried running <em>ndk-build V=1</em> to check the actual linking command, and <em>libavcodec</em> is sitting there perfectly right, like it should. All other ffmpeg libs are there too.</p>
  
  <p>Any hints?</p>