title: How to link libavcodec, libavformat in automake?
body: <p>I am using the libavcodec and libavformat libraries from ffmpeg in a C++ project. Linking -lavcodec -lavformat with the g++ compiler works fine, but I'm not sure what goes wrong when I try to use the same code compiled in an automake project.</p>
  
  <p>Working fine:</p>
  
  <pre><code>g++ -o test -D__STDC_CONSTANT_MACROS -lavcodec -lavformat test.cpp
  </code></pre>
  
  <p>Not working Makefile.am:</p>
  
  <pre><code>binaryname_LDFLAGS= -lavcodec -lavformat
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>....
  /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function 
  ff_nut_add_sp: error: undefined reference to 'av_tree_node_size'
  /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function 
  ff_nut_add_sp: error: undefined reference to 'av_tree_insert'
  /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function 
  ff_nut_free_sp: error: undefined reference to 'av_tree_enumerate'
  /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function 
  ff_nut_free_sp: error: undefined reference to 'av_tree_destroy'
  /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(rtp.o):function 
  ff_rtp_get_payload_type: error: undefined reference to 'av_opt_get_int'
  ...
  </code></pre>
  
  <p>also not working:</p>
  
  <pre><code>LDFLAGS=...-lavcodec -lavformat
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>src/dsp/audioDecoder.cpp:99: error: undefined reference to 'av_register_all'
  src/dsp/audioDecoder.cpp:101: error: undefined reference to 'avcodec_find_decoder'
  src/dsp/audioDecoder.cpp:109: error: undefined reference to 'avcodec_alloc_context'
  src/dsp/audioDecoder.cpp:120: error: undefined reference to 'avcodec_open2'
  src/dsp/audioDecoder.cpp:125: error: undefined reference to 'av_init_packet'
  src/dsp/audioDecoder.cpp:188: error: undefined reference to 'avcodec_decode_audio3'
  </code></pre>
  
  <p>In the second case, if I don't set any linker, the include header cannot be found so the linker seems somehow recognized.</p>
  
  <p>make V=1 returns:</p>
  
  <pre><code>make  all-am
  make[1]: Go to '/path/to/trunk'
  /bin/bash ./libtool --tag=CXX   --mode=link g++  -O2 -lrt -D__STDC_CONSTANT_MACROS   -o binaryname progsrc/binaryname/binaryname-binaryname.o    -lm  -lpthread -ldl -lmygeneratedlibrary
  libtool: link: g++ -O2 -D__STDC_CONSTANT_MACROS -o binaryname progsrc/binaryname/binaryname-binaryname.o  -lm /path/to//trunk/.libs/lmygeneratedlibrary.a -lrt -lavutil -lavcodec -lavformat -lpthread -ldl
  make[1]: Leave '/path/to/trunk'
  </code></pre>
  
  <p>What am I doing wrong here?</p>