报错如下
wcx@wcx:~/Desktop/ffmpegtest/build$ sudo make
Scanning dependencies of target wcx
[ 50%] Building CXX object CMakeFiles/wcx.dir/main.cpp.o
[100%] Linking CXX executable wcx
/usr/bin/ld: CMakeFiles/wcx.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x3c): undefined reference to `avformat_open_input(AVFormatContext**, char const*, AVInputFormat const*, AVDictionary**)'
/usr/bin/ld: main.cpp:(.text+0x88): undefined reference to `avformat_find_stream_info(AVFormatContext*, AVDictionary**)'
/usr/bin/ld: main.cpp:(.text+0x141): undefined reference to `avcodec_alloc_context3(AVCodec const*)'
/usr/bin/ld: main.cpp:(.text+0x158): undefined reference to `avcodec_parameters_to_context(AVCodecContext*, AVCodecParameters const*)'
/usr/bin/ld: main.cpp:(.text+0x166): undefined reference to `avcodec_find_decoder(AVCodecID)'
/usr/bin/ld: main.cpp:(.text+0x193): undefined reference to `avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)'
/usr/bin/ld: main.cpp:(.text+0x1d1): undefined reference to `sws_getContext(int, int, AVPixelFormat, int, int, AVPixelFormat, int, SwsFilter*, SwsFilter*, double const*)'
/usr/bin/ld: main.cpp:(.text+0x235): undefined reference to `av_packet_alloc()'
/usr/bin/ld: main.cpp:(.text+0x24c): undefined reference to `av_read_frame(AVFormatContext*, AVPacket*)'
/usr/bin/ld: main.cpp:(.text+0x26e): undefined reference to `av_frame_alloc()'
/usr/bin/ld: main.cpp:(.text+0x285): undefined reference to `avcodec_send_packet(AVCodecContext*, AVPacket const*)'
/usr/bin/ld: main.cpp:(.text+0x2a5): undefined reference to `avcodec_receive_frame(AVCodecContext*, AVFrame*)'
/usr/bin/ld: main.cpp:(.text+0x3af): undefined reference to `av_frame_free(AVFrame**)'
/usr/bin/ld: main.cpp:(.text+0x3bb): undefined reference to `av_packet_unref(AVPacket*)'
/usr/bin/ld: main.cpp:(.text+0x3cc): undefined reference to `av_packet_free(AVPacket**)'
/usr/bin/ld: main.cpp:(.text+0x3d8): undefined reference to `avcodec_free_context(AVCodecContext**)'
/usr/bin/ld: main.cpp:(.text+0x3e4): undefined reference to `avformat_close_input(AVFormatContext**)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/wcx.dir/build.make:84: wcx] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/wcx.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
解决:检查CMake 所有配置都没有问题后 确认缺少 extern “C”
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}