[FFmpeg-devel] library linking question

Chau Pham chaupv79 at hotmail.com
Tue Jul 10 02:37:39 CEST 2012

Hi Guys, 

I compiled ffmpeg-0.11.1 on linux, I want to use its library and header in a small specific c program to use av_register_all() in ffmpeg library,
I am having trouble in linking ffmpeg.

0) I use Centos 5.7 for a linux machine.
1) I have compiled ffmpeg-0.11.1 in /root/ffmpeg-source/working/ffmpeg
2) I make a test.c in /root/ffmpeg-source/working/test.c as below:

#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>

#include <stdio.h>
int main()
        //printf("Test FFmpeg library! \n");
        return 1;

3) I make a Makefile in /root/ffmpeg-source/working/ as below:

PROGRAM = test

LIBS = -L$(root/ffmpeg-source/working/ffmpeg/libavformat/)libavformat.a -L$(root/ffmpeg-source/working/ffmpeg/libavcodec/)libavcodec.a

CXXSOURCES = test.c       # list of source files
CXXOBJECTS = $(CXXSOURCES:.c=.o)  # expands to list of object files
CXX = gcc


all: $(PROGRAM)

        $(CXX) -o $@ $(CXXOBJECTS) $(LDFLAGS) -static

test.o: test.c
        $(CXX) $(HEADERFLAGS) -c -o test.o test.c

        $(RM) -f $(CXXOBJECTS) $(PROGRAM)

=> When I compile:

[root at FFMPEG working]# make -f Makefile
gcc -o test test.o   -Llibavformat.a -Llibavcodec.a -static
test.o: In function `main':
test.c:(.text+0x12): undefined reference to `av_register_all'
collect2: ld returned 1 exit status
make: *** [test] Error 1

I bet you guys will have a laugh when read to here, because you think that I am a 'chicken' on this master :)) , it's Ok, 
please help me if you find out the reason why the error occurs. (I think, it's on library linking problem)

Do you guy have experience on that? could you show me a hint how to do it?

Look forward to hearing from you soon,

Thank You,
Chau Pham

More information about the ffmpeg-devel mailing list