[Libav-user] 'Undefined reference'-error when using functions of libavcodec, compiling in Linux

Andrey Utkin andrey.krieger.utkin at gmail.com
Fri Mar 16 14:29:08 CET 2012

2012/3/16 Anders Branderud <anders.branderud at gmail.com>:
> Hello!
> When I run the encoding example (code inserted to the following cc-file)
> provided in doc/examples of the FFMpeg-library and compile it with the
> line linux-y8h9:/home/anders/Programs # g++ videofecencoder.cc -lavformat
> -lavcodec -lavutil
> I get the following error message:
> /tmp/ccDQpTY5.o: In function `video_encode_example(char const*, int)':
> videofecencoder.cc:(.text+0x30): undefined reference to
> `avcodec_find_encoder(CodecID)'
> videofecencoder.cc:(.text+0x75): undefined reference to
> `avcodec_alloc_context3(AVCodec*)'
> videofecencoder.cc:(.text+0x7d): undefined reference to
> `avcodec_alloc_frame()'
> videofecencoder.cc:(.text+0xfc): undefined reference to `av_opt_set(void*,
> char const*, char const*, int)'
> videofecencoder.cc:(.text+0x116): undefined reference to
> `avcodec_open2(AVCodecContext*, AVCodec*, AVDictionary**)'
> videofecencoder.cc:(.text+0x1e2): undefined reference to
> `av_image_alloc(unsigned char**, int*, int, int, PixelFormat, int)'
> videofecencoder.cc:(.text+0x330): undefined reference to
> `avcodec_encode_video(AVCodecContext*, unsigned char*, int, AVFrame const*)'
> videofecencoder.cc:(.text+0x3b3): undefined reference to
> `avcodec_encode_video(AVCodecContext*, unsigned char*, int, AVFrame const*)'
> videofecencoder.cc:(.text+0x464): undefined reference to
> `avcodec_close(AVCodecContext*)'
> videofecencoder.cc:(.text+0x46f): undefined reference to `av_free(void*)'
> videofecencoder.cc:(.text+0x47c): undefined reference to `av_free(void*)'
> videofecencoder.cc:(.text+0x487): undefined reference to `av_free(void*)'
> /tmp/ccDQpTY5.o: In function `main':
> videofecencoder.cc:(.text+0x4a8): undefined reference to
> `avcodec_register_all()'
> collect2: ld returned 1 exit status
> I have tried the same using two different Ubuntu-installations. The above
> compilation was performed using OpenSUSE installed in a VirtualBox. I did
> the above at a new installation of OpenSUSE. After installing it I
> downloaded the required libraries using the libraries provided in the
> Software repository called 'PackMan'.

You lack libraries' header files. Find and install packages that
contain files /usr/include/libavformat/avformat.h,
/usr/include/libavcodec/avcodec.h . I hope you got the point. I don't
know exact package names for suse and ubuntu.

Andrey Utkin

More information about the Libav-user mailing list