2

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.

4

2 回答 2

9

最后,我设法编译了使用 ffmpeg 库的程序。

出于某种原因,我仍然无法使用 gcc 编译器编译它,但我可以使用 g++ 编译器来编译它。

安装静态库时,必须明确指定所有依赖项,并且这些库的链接顺序也很重要。所以这是最终编译我的程序的编译代码:

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

pkg-config这是一个实用程序,它打印正确链接指定库所需的所有标志和libavformat库。

另外值得一提的是,源文件已从 readVideo.C 重命名为 readVideo.cc,并且该#include语句已包含使用extern "C"如下:

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

它是必需的,因为 ffmpeg 是一个 C 项目,如果您没有明确声明它是 C 库,程序将无法使用 C++ 编译器进行编译。

如果您不想费心pkg-config包含 ffmpeg 库的所有依赖项,您可以使用共享库而不是静态库安装 ffmpeg。然后它将通过更简单的调用进行编译:

g++ readVideo.cc -o readVideo -lavformat

要安装共享库,需要./configure在安装ffmpeg时在program中添加这2个选项:

--disable-static --enable-shared

希望它可以帮助某人一段时间...

于 2012-11-15T12:54:11.147 回答
0

该错误意味着您没有链接到 ffmpeg 库。仅仅包括头文件是不够的。您还需要链接到实际的库文件。在 Windows 上,它们有 .lib 扩展名,在 Linux 上通常是 .a 扩展名,不确定 Mac。

于 2012-10-16T09:18:49.263 回答