CMake:undefined reference to xxxx

报错如下

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>
}
  • 11
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值