Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilation error using ffmpeg library

I have downloaded and installed the ffmpeg library. I want to use it for reading the separate frames of different videos and manipulate them. For that I tried to follow some tutorial from here: http://dranger.com/ffmpeg/tutorial01.html But I can't compile my cpp file since I get the following compilation:

Undefined symbols for architecture x86_64:
  "av_register_all()", referenced from:
      _main in cc9zyUBe.o
      _main in ccRz35d4.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

When I was installing ffmpeg library, I used arch=x86_64 option in ./configure step. I use OS X Mountain Lion 10.8.2 and gcc 4.2 compiler. Does somebody have any clue what can be the reason of this error? Thanks in advance.

UPDATE: I've already tried many different install options, with static libraries, shared libraries, with/without --arch=x86_64 option. Also installed it with homebrew, result remains the same. Library isn't recognized. But ffmpeg binary works pretty well, when I use it as a command-line tool.

like image 699
BartoNaz Avatar asked Aug 10 '26 16:08

BartoNaz


1 Answers

Finally I have managed to compile my program which uses ffmpeg library.

For some reason I still couldn't compile it using gcc compiler, but I could do it with g++ compiler.

When the static libraries are installed, all the dependencies must be specified explicitly, and the order of linking of these libraries is also important. So here is the compilation code which finally compiled my program:

g++ readVideo.cc -o readVideo $(pkg-config --libs --cflags libavformat)

pkg-config here is a utility which prints all the flags and libraries that are needed to properly link the specified libavformat library.

Also it's worth of mentioning, that the source file was renamed from readVideo.C to readVideo.cc, and that #include statements have been encompassed using extern "C" as follows:

extern "C" {
  #include <libavformat/avformat.h>
}

It is needed because ffmpeg is a C project and program will not compile with C++ compiler if you don't explicitly state that it is C library.

And if you don't want to bother with pkg-config to include all dependencies for ffmpeg libraries, you can install ffmpeg with shared libraries instead of static ones. Then it will compile by simpler call:

g++ readVideo.cc -o readVideo -lavformat

To install shared libraries, you need to add these 2 options to ./configure program when installing ffmpeg:

--disable-static --enable-shared

Hope it helps somebody some time ...

like image 173
BartoNaz Avatar answered Aug 12 '26 10:08

BartoNaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!