ffmpeg庫使用,undefined reference錯誤
ffmpeg用g++編譯時的注意事項
編譯時出現以下錯誤:
錯誤一:
undefined reference to `av_register_all()' undefined reference to `avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)' undefined reference to `avformat_find_stream_info(AVFormatContext*, AVDictionary**)' undefined reference to `avcodec_find_decoder(AVCodecID)' undefined reference to `avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)' undefined reference to `avcodec_alloc_frame()' undefined reference to `avcodec_alloc_frame()'
解決方法: 用extern "C"{}把標頭檔案包含起來。 extern "C" { #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libswscale/swscale.h> }
錯誤二:
ffmpeg_4.0.2/lib/libavcodec.a(tiff.o): In function `tiff_uncompress_lzma': ffmpeg-4.0.2/libavcodec/tiff.c:398: undefined reference to `lzma_stream_decoder' ffmpeg-4.0.2/libavcodec/tiff.c:403: undefined reference to `lzma_code' ffmpeg-4.0.2/libavcodec/tiff.c:404: undefined reference to `lzma_end'
解決方法:加上-llzma選項
參考的編譯選項:
gcc push.cpp -g -I ffmpeg_4.0.2/include -L ffmpeg_4.0.2/lib -lavform個人中心at -lavcodec -lswresample -lavutil -pthread -lbz2 -lz -lm -llzma