title: Including ffmpeg in C program
body: <p>I'm using dranger's ffmpeg tutorial:</p>
  
  <p><a href="http://dranger.com/ffmpeg/tutorial01.html" rel="nofollow">http://dranger.com/ffmpeg/tutorial01.html</a></p>
  
  <p>I'm stuck trying to compile the first tutorial. I downloaded ffmpeg using homebrew, but the compile command provided in the tutorial did not work:</p>
  
  <p><code>gcc -o tutorial01 tutorial01.c -lavutil -lavformat -lavcodec -lz -lavutil -lm</code></p>
  
  <p>Based on my experience with SDL, I made a separate file that simply included one of the ffmpeg headers, and changed the compile command to:</p>
  
  <p><code>gcc main.c -I/usr/local/Cellar/ffmpeg/2.6.1/include</code></p>
  
  <p>It was actually able to compile. But when I tried this with the tutorial file using this command:</p>
  
  <p><code>gcc tutorial01.c -I/usr/local/Cellar/ffmpeg/2.6.1/include</code></p>
  
  <p>I got these errors:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "_av_dump_format", referenced from:
        _main in tutorial01-9cd32b.o
    "_av_frame_alloc", referenced from:
        _main in tutorial01-9cd32b.o
    "_av_frame_free", referenced from:
        _main in tutorial01-9cd32b.o
    "_av_free", referenced from:
        _main in tutorial01-9cd32b.o
    "_av_free_packet", referenced from:
        _main in tutorial01-9cd32b.o
    "_av_malloc", referenced from:
        _main in tutorial01-9cd32b.o
    "_av_read_frame", referenced from:
        _main in tutorial01-9cd32b.o
    "_av_register_all", referenced from:
        _main in tutorial01-9cd32b.o
    "_avcodec_alloc_context3", referenced from:
        _main in tutorial01-9cd32b.o
    "_avcodec_close", referenced from:
        _main in tutorial01-9cd32b.o
    "_avcodec_copy_context", referenced from:
        _main in tutorial01-9cd32b.o
    "_avcodec_decode_video2", referenced from:
        _main in tutorial01-9cd32b.o
    "_avcodec_find_decoder", referenced from:
        _main in tutorial01-9cd32b.o
    "_avcodec_open2", referenced from:
        _main in tutorial01-9cd32b.o
    "_avformat_close_input", referenced from:
        _main in tutorial01-9cd32b.o
    "_avformat_find_stream_info", referenced from:
        _main in tutorial01-9cd32b.o
    "_avformat_open_input", referenced from:
        _main in tutorial01-9cd32b.o
    "_avpicture_fill", referenced from:
        _main in tutorial01-9cd32b.o
    "_avpicture_get_size", referenced from:
        _main in tutorial01-9cd32b.o
    "_sws_getContext", referenced from:
        _main in tutorial01-9cd32b.o
    "_sws_scale", referenced from:
        _main in tutorial01-9cd32b.o
  </code></pre>
  
  <p>I figured I had to add the extra things from the tutorial, so I did</p>
  
  <p><code>gcc tutorial01.c -I/usr/local/Cellar/ffmpeg/2.6.1/include -lavutil -lavformat -lavcodec -lz -lavutil -lm</code></p>
  
  <p>But then I got this error</p>
  
  <pre><code>ld: library not found for -lavutil
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make: *** [all] Error 1
  </code></pre>
  
  <p>I feel like the directory <code>/usr/local/Cellar/ffmpeg/2.6.1/lib</code> might be relevant, it includes the files:</p>
  
  <pre><code>libavcodec.56.26.100.dylib  libavresample.dylib
  libavcodec.56.dylib         libavutil.54.20.100.dylib
  libavcodec.a                libavutil.54.dylib
  libavcodec.dylib            libavutil.a
  libavdevice.56.4.100.dylib  libavutil.dylib
  libavdevice.56.dylib        libpostproc.53.3.100.dylib
  libavdevice.a               libpostproc.53.dylib
  libavdevice.dylib           libpostproc.a
  libavfilter.5.11.102.dylib  libpostproc.dylib
  libavfilter.5.dylib         libswresample.1.1.100.dylib
  libavfilter.a               libswresample.1.dylib
  libavfilter.dylib           libswresample.a
  libavformat.56.25.101.dylib libswresample.dylib
  libavformat.56.dylib        libswscale.3.1.101.dylib
  libavformat.a               libswscale.3.dylib
  libavformat.dylib           libswscale.a
  libavresample.2.1.0.dylib   libswscale.dylib
  libavresample.2.dylib       pkgconfig
  libavresample.a
  </code></pre>
  
  <p>I'm often really lost trying to compile downloaded libraries (it took me a long time to get SDL to compile, and when I finally got it to work I still didn't completely understand why).</p>
  
  <p>If anyone could help me understand how these things work, and specifically help me compile this first tutorial, I would be extremely grateful.</p>
  
  <p>Thank you for your time.</p>