编译ffmpeg例程时,报错:undefined reference

编译ffmpeg例程,报了未定义错误:

main.cpp:(.text+0x3a): undefined reference to avcodec_send_frame(AVCodecContext*, AVFrame const*)'
main.cpp:(.text+0x8c): undefined reference to
av_packet_unref(AVPacket*)’
main.cpp:(.text+0x97): undefined reference to avcodec_receive_packet(AVCodecContext*, AVPacket*)'
build/src/main.cpp.o: In function
main’:
main.cpp:(.text.startup+0x4b): undefined reference to avcodec_register_all()'
main.cpp:(.text.startup+0x53): undefined reference to
avcodec_find_encoder_by_name(char const*)’
main.cpp:(.text.startup+0x5d): undefined reference to avcodec_find_encoder(AVCodecID)'
main.cpp:(.text.startup+0x71): undefined reference to
avcodec_alloc_context3(AVCodec const*)’
main.cpp:(.text.startup+0x84): undefined reference to av_packet_alloc()'
main.cpp:(.text.startup+0xf9): undefined reference to
avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)’
main.cpp:(.text.startup+0x11f): undefined reference to av_frame_alloc()'
main.cpp:(.text.startup+0x154): undefined reference to
av_frame_get_buffer(AVFrame*, int)’
main.cpp:(.text.startup+0x182): undefined reference to av_frame_make_writable(AVFrame*)'
main.cpp:(.text.startup+0x2f0): undefined reference to
avcodec_free_context(AVCodecContext**)’
main.cpp:(.text.startup+0x2fa): undefined reference to av_frame_free(AVFrame**)'
main.cpp:(.text.startup+0x304): undefined reference to
av_packet_free(AVPacket**)’
main.cpp:(.text.startup+0x3aa): undefined reference to `av_opt_set(void*, char const*, char const*, int)’

原因:
ffmpeg是纯C的库,头文件没有做好C++调用的准备
用extern “C”{}套住ffmpeg头文件,用C语言的编译规则来编译ffmpeg代码,就可以了

你可能感兴趣的:(编程语言/设计模式)