Wednesday, November 14, 2007

FFmpeg g++ and linking

I wasn't able to build a c++ program that makes use of ffmpeg libraries (libavcodec, libavutil and libavforamt).
After some tries and fails I found that in order to link correctly ffmpeg within a c++ program using g++ you need to include ffmpeg in this way:
extern "C"
{
#include "ffmpeg/avcodec.h"
#include "ffmpeg/swscale.h"
#include "ffmpeg/avformat.h"
}
(blogger don't like ffmpeg includes!!!!)

This is not needed for example in vc++.
If not doing so you will keep on getting "undefined reference" errors while linking with g++.

This is an example of building with g++ statically linking to ffmpeg:
g++ ...some options... /usr/local/lib/libavcodec.a /usr/local/lib/libavformat.a /usr/local/lib/libavutil.a /usr/lib/libz.a /usr/lib/libm.a