1. 程式人生 > >編譯ffmpeg例程時,報錯:undefined reference

編譯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程式碼,就可以了