title: Trouble linking ffmpeg example source code
body: <p>I managed to build ffmpeg and libx264 on my Ubuntu 11.10 machine from source. </p>
  
  <p>I'm trying to work on the example source file decoding_encoding.c. The examples comes with a makefile, so I can just type in "make all" and it magically compiles and links everything. Now, I'm trying to compile and link from the command line but I can't seem to get it to link.</p>
  
  <p>Here is the makefile:</p>
  
  <pre><code># use pkg-config for getting CFLAGS abd LDFLAGS
  FFMPEG_LIBS=libavdevice libavformat libavfilter libavcodec libswscale libavutil
  CFLAGS+=$(shell pkg-config  --cflags $(FFMPEG_LIBS))
  LDFLAGS+=$(shell pkg-config --libs $(FFMPEG_LIBS))
  
  EXAMPLES=decoding_encoding filtering metadata muxing
  
  OBJS=$(addsuffix .o,$(EXAMPLES))
  
  %: %.o
          $(CC) $&lt; $(LDFLAGS) -o $@
  
  %.o: %.c
          $(CC) $&lt; $(CFLAGS) -c -o $@
  
  .phony: all clean
  
  all: $(OBJS) $(EXAMPLES)
  
  clean:
          rm -rf $(EXAMPLES) $(OBJS)
  </code></pre>
  
  <p>I can compile the source using this:</p>
  
  <pre><code>gcc -Wall -I/usr/local/include -c -o decoding_encoding.o decoding_encoding.c
  </code></pre>
  
  <p>When I try to link using this:</p>
  
  <pre><code>gcc -Wall -L/usr/local/lib -lavdevice -lavformat -lavfilter -lavcodec -lswscale -lavutil -o decoding_encoding decoding_encoding.o
  </code></pre>
  
  <p>At this point, I get a huge list of 'undefined reference error' </p>
  
  <pre><code>decoding_encoding.o: In function `audio_encode_example':
  decoding_encoding.c:(.text+0x25): undefined reference to `avcodec_find_encoder'
  decoding_encoding.c:(.text+0x6a): undefined reference to `avcodec_alloc_context3'
  decoding_encoding.c:(.text+0xad): undefined reference to `avcodec_open'
  decoding_encoding.c:(.text+0x1ce): undefined reference to `sin'
  decoding_encoding.c:(.text+0x238): undefined reference to `avcodec_encode_audio'
  decoding_encoding.c:(.text+0x297): undefined reference to `avcodec_close'
  decoding_encoding.c:(.text+0x2a3): undefined reference to `av_free'
  decoding_encoding.o: In function `audio_decode_example':
  decoding_encoding.c:(.text+0x2f7): undefined reference to `av_init_packet'
  decoding_encoding.c:(.text+0x30b): undefined reference to `avcodec_find_decoder'
  decoding_encoding.c:(.text+0x359): undefined reference to `avcodec_alloc_context3'
  decoding_encoding.c:(.text+0x379): undefined reference to `avcodec_open'
  ..... etc.
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>Am I doing something wrong with my linker command? I've examined the makefile and I believe that I'm doing exactly what the makefile is....or am I? </p>
  
  <p>Thanks,</p>
  
  <p>Leo</p>