在构建关于ffmpeg的演示时,会发生:对`av_register_all'的未定义引用

Cod*_*ody 6 ffmpeg

这个问题困扰了我好几天.

在编译并安装ffmpeg之后,我尝试使用它构建一个演示,但它总是失败.

该演示是:

#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"

int main(int argc,char *argv[]) {
    av_register_all();
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

gcc main.c -o main.o,出现错误:undefined reference to 'av_register_all'

使用:构建,gcc main.c -o main.o -lm -ld -lz -lavcodec -lavformat -lavutil发生另一个错误:/usr/bin/ld: cannot find -ld

我该如何解决这个问题?

ruw*_*800 11

在extern"C"块中放置包含可能有效.

extern "C"{
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    #include <libswscale/swscale.h>
}
Run Code Online (Sandbox Code Playgroud)


mpe*_*kov 1

看看这个项目如何构建示例代码。

Makefile 非常容易理解。