编译ffmpeg例程,报了未定义错误:
main.cpp:(.text+0x3a): undefined reference to
avcodec_send_frame(AVCodecContext*, AVFrame const*)'
av_packet_unref(AVPacket*)’
main.cpp:(.text+0x8c): undefined reference to
main.cpp:(.text+0x97): undefined reference toavcodec_receive_packet(AVCodecContext*, AVPacket*)'
main’:
build/src/main.cpp.o: In function
main.cpp:(.text.startup+0x4b): undefined reference toavcodec_register_all()'
avcodec_find_encoder_by_name(char const*)’
main.cpp:(.text.startup+0x53): undefined reference to
main.cpp:(.text.startup+0x5d): undefined reference toavcodec_find_encoder(AVCodecID)'
avcodec_alloc_context3(AVCodec const*)’
main.cpp:(.text.startup+0x71): undefined reference to
main.cpp:(.text.startup+0x84): undefined reference toav_packet_alloc()'
avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)’
main.cpp:(.text.startup+0xf9): undefined reference to
main.cpp:(.text.startup+0x11f): undefined reference toav_frame_alloc()'
av_frame_get_buffer(AVFrame*, int)’
main.cpp:(.text.startup+0x154): undefined reference to
main.cpp:(.text.startup+0x182): undefined reference toav_frame_make_writable(AVFrame*)'
avcodec_free_context(AVCodecContext**)’
main.cpp:(.text.startup+0x2f0): undefined reference to
main.cpp:(.text.startup+0x2fa): undefined reference toav_frame_free(AVFrame**)'
av_packet_free(AVPacket**)’
main.cpp:(.text.startup+0x304): undefined reference to
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代码,就可以了