ffmpeg linker problems

1,424 views
Skip to first unread message

BerlinerMC

unread,
Nov 8, 2010, 1:26:49 PM11/8/10
to android-ndk
Hello Android-NDK group,

i have successful compiled ffmpeg with the ndk-crystax.
Then i created a new cpp class and included some ffmpeg features.

Now i get some "undefined reference to" errors:

/home/alex/AndroidFfmpeg/jni/ffmpegtest/FFMpegTests.cpp:26: undefined
reference to `av_register_all'
/home/alex/AndroidFfmpeg/jni/ffmpegtest/FFMpegTests.cpp:41: undefined
reference to `av_open_input_file'
/home/alex/AndroidFfmpeg/jni/ffmpegtest/FFMpegTests.cpp:46: undefined
reference to `av_find_stream_info'

My Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_ALLOW_UNDEFINED := TRUE
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../ffmpeg/
LOCAL_LDLIBS := -L /home/alex/AndroidFfmpeg/obj/local/armeabi -lffmpeg
LOCAL_STATIC_LIBRARIES += avformat avcodec avutil postproc swscale

LOCAL_MODULE := ffmpegtests
LOCAL_SRC_FILES := FFMpegTests.cpp

include $(BUILD_SHARED_LIBRARY)

So any ideas how i can solve this problem?!
Thanks for help
Alex / Berliner

Eugene Mymrin

unread,
Nov 8, 2010, 3:38:53 PM11/8/10
to andro...@googlegroups.com
When including FFmpeg headers from cpp code use extern "C" notation:
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavutil/avutil.h"
#include "libavformat/avformat.h"
}

> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>
>

Mike Edenfield

unread,
Nov 8, 2010, 5:50:41 PM11/8/10
to android-ndk
On Nov 8, 1:26 pm, BerlinerMC <a.deutschm...@online.de> wrote:

> Now i get some "undefined reference to" errors:
>
> /home/alex/AndroidFfmpeg/jni/ffmpegtest/FFMpegTests.cpp:26: undefined
> reference to `av_register_all'
> /home/alex/AndroidFfmpeg/jni/ffmpegtest/FFMpegTests.cpp:41: undefined
> reference to `av_open_input_file'
> /home/alex/AndroidFfmpeg/jni/ffmpegtest/FFMpegTests.cpp:46: undefined
> reference to `av_find_stream_info'

> LOCAL_STATIC_LIBRARIES += avformat avcodec avutil postproc swscale

Are the ffmpeg libraries in the output folder already (obj/local/
armeabi) already? If you built them with the ndk-build system they
should be; if you're cross-compiling them you need to install them in
the correct place, or specify a complete relative path to them like
so:

LOCAL_STATIC_LIBRARIES += /../../../../libs/libavutil

If this is your problem, you should also be setting earlier linker
errors about being unable to find the libraries in question.

BerlinerMC

unread,
Nov 9, 2010, 4:17:39 PM11/9/10
to android-ndk
Thanks for your reply :)

@Eugene: I included it allready with extern "C". Next time i will post
my .cpp file too. Sorry
@Mike: Yes i compiled it with the android ndk-build system. These .a
files are in "obj/local/armeabi"

I used now the source code from another project which used ffmpeg!
http://power-amp.info/
I compiled it successful and i get no "reference to" errors.
I pushed the libffmpeg.so to the /data/data/ffmpegtest/lib folder!
But now if i started the app on an emulator (2.1), then the app broke.

My .cpp file:

int FFMpegTests::showFilmInformation() {

av_register_all();

AVFormatContext *pFormatCtx;

const char* filename = "/sdcard/test.avi";
if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL) != 0) {
return -1; //Couldn't open file
}
}

After av_open_input_file i get an "fingerprint" error from DDMS.
In the Manifest file i used the permission
"android.permission.WRITE_EXTERNAL_STORAGE"
but no success.

I hope you can help me :)
Should i open a new thread or can i use this thread?!

Thanks for your help
Alex / Berliner

BerlinerMC

unread,
Nov 11, 2010, 6:25:38 AM11/11/10
to android-ndk
I have solved my problem!
You have to add this in your Android.mk
LOCAL_LDLIBS += -llog -lavutil -lavformat -lavcodec -lz -lavutil -lm

everything works fine now. Thanks for your help :)

On Nov 9, 10:17 pm, BerlinerMC <a.deutschm...@online.de> wrote:
> Thanks for your reply :)
>
> @Eugene: I included it allready with extern "C". Next time i will post
> my .cpp file too. Sorry
> @Mike: Yes i compiled it with the android ndk-build system. These .a
> files are in "obj/local/armeabi"
>
> I used now the source code from another project which used ffmpeg!http://power-amp.info/
Reply all
Reply to author
Forward
0 new messages