eclipse 使用 libav 时出现未定义引用

eclipse 使用 libav 时出现未定义引用

我正在尝试从libav 网站。当前版本为 11.7。我已经解压、配置、制作并安装。

对于 ./configure,我尝试使用各种选项。作为预防措施,如果我使用 ./configure 添加/删除选项,我会使用源代码的新副本执行此操作,并清除库和标头。

附加选项包括:

./configure --enable-libx264 --enable-librtmp --enable-gpl --enable-nonfree --enable-muxer=mp4 --enable-muxer=h264 --enable-demuxer=aac --enable-demuxer=h264 --enable-encoder=libx264 --enable-encoder=libfdk_aac --enable-decoder=libfdk_aac --enable-version3

我也厌倦了没有任何其他选择。

在 eclipse IDE 中,我已将编译器配置为将 /usr/local/libs 包含在其搜索路径中,并且还包括库本身。 Eclipse c++ 库/搜索路径

我不知道还能做什么。我一直收到未定义的引用。

编辑(附加信息):我已将代码简化为仅包含函数 av_register_all();。但仍然出现错误。以下是一些错误:

/usr/local/lib/libavcodec.a(libx264.o): In function `X264_frame':
/usr/local/src/libav/libavcodec/libx264.c:140: undefined reference to `x264_picture_init'
/usr/local/src/libav/libavcodec/libx264.c:142: undefined reference to `x264_bit_depth'
/usr/local/src/libav/libavcodec/libx264.c:160: undefined reference to `x264_encoder_reconfig'
/usr/local/src/libav/libavcodec/libx264.c:166: undefined reference to `x264_encoder_reconfig'
/usr/local/src/libav/libavcodec/libx264.c:173: undefined reference to `x264_encoder_reconfig'
/usr/local/src/libav/libavcodec/libx264.c:192: undefined reference to `x264_encoder_reconfig'
/usr/local/src/libav/libavcodec/libx264.c:232: undefined reference to `x264_encoder_reconfig'
/usr/local/src/libav/libavcodec/libx264.c:237: undefined reference to `x264_encoder_encode'
/usr/local/src/libav/libavcodec/libx264.c:243: undefined reference to `x264_encoder_delayed_frames'
/usr/local/src/libav/libavcodec/libx264.c:237: undefined reference to `x264_encoder_encode'
/usr/local/src/libav/libavcodec/libx264.c:179: undefined reference to `x264_encoder_reconfig'
/usr/local/src/libav/libavcodec/libx264.c:198: undefined reference to `x264_encoder_reconfig'
/usr/local/src/libav/libavcodec/libx264.c:186: undefined reference to `x264_encoder_reconfig'
/usr/local/lib/libavcodec.a(libx264.o): In function `X264_init_static':
/usr/local/src/libav/libavcodec/libx264.c:577: undefined reference to `x264_bit_depth'
/usr/local/lib/libavcodec.a(libx264.o): In function `X264_close':
/usr/local/src/libav/libavcodec/libx264.c:278: undefined reference to `x264_encoder_close'
/usr/local/lib/libavcodec.a(libx264.o): In function `X264_init':
/usr/local/src/libav/libavcodec/libx264.c:314: undefined reference to `x264_param_default'
/usr/local/src/libav/libavcodec/libx264.c:319: undefined reference to `x264_param_default_preset'
/usr/local/src/libav/libavcodec/libx264.c:415: undefined reference to `x264_param_parse'
/usr/local/src/libav/libavcodec/libx264.c:416: undefined reference to `x264_param_parse'
/usr/local/src/libav/libavcodec/libx264.c:417: undefined reference to `x264_param_parse'
/usr/local/src/libav/libavcodec/libx264.c:418: undefined reference to `x264_param_parse'
/usr/local/src/libav/libavcodec/libx264.c:459: undefined reference to `x264_param_apply_fastfirstpass'
/usr/local/src/libav/libavcodec/libx264.c:465: undefined reference to `x264_param_apply_profile'
/usr/local/src/libav/libavcodec/libx264.c:501: undefined reference to `x264_param_parse'
/usr/local/src/libav/libavcodec/libx264.c:519: undefined reference to `x264_encoder_open_148'
/usr/local/src/libav/libavcodec/libx264.c:532: undefined reference to `x264_encoder_headers'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_subpacket':
/usr/local/src/libav/libavcodec/opusdec.c:382: undefined reference to `avresample_is_open'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_frame':
/usr/local/src/libav/libavcodec/opusdec.c:221: undefined reference to `avresample_is_open'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_init_resample':
/usr/local/src/libav/libavcodec/opusdec.c:163: undefined reference to `avresample_open'
/usr/local/src/libav/libavcodec/opusdec.c:169: undefined reference to `avresample_convert'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_frame':
/usr/local/src/libav/libavcodec/opusdec.c:236: undefined reference to `avresample_convert'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_flush_resample':
/usr/local/src/libav/libavcodec/opusdec.c:118: undefined reference to `avresample_convert'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_subpacket':
/usr/local/src/libav/libavcodec/opusdec.c:414: undefined reference to `avresample_close'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_flush':
/usr/local/src/libav/libavcodec/opusdec.c:616: undefined reference to `avresample_close'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_close':
/usr/local/src/libav/libavcodec/opusdec.c:640: undefined reference to `avresample_free'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_init':
/usr/local/src/libav/libavcodec/opusdec.c:704: undefined reference to `avresample_alloc_context'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `ff_frame_thread_free':
/usr/local/src/libav/libavcodec/pthread_frame.c:522: undefined reference to `pthread_join'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `ff_frame_thread_init':
/usr/local/src/libav/libavcodec/pthread_frame.c:648: undefined reference to `pthread_create'
/usr/local/lib/libavcodec.a(pthread_slice.o): In function `ff_slice_thread_free':
/usr/local/src/libav/libavcodec/pthread_slice.c:110: undefined reference to `pthread_join'
/usr/local/lib/libavcodec.a(pthread_slice.o): In function `ff_slice_thread_init':
/usr/local/src/libav/libavcodec/pthread_slice.c:211: undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status

更具体地说,库安装在 /usr/local/lib 目录中,头安装在 /usr/local/include/libav* 中。我也尝试过通过命令行而不是 IDE 来编译我的源代码,结果相同。

命令行参数:

c++ -L/usr/local/lib test.cpp -lx264 -lavresample -lavformat -lavutil -lavcodec -lavutil -lz -lavutil -o out

答案1

确保您有这个块:

extern "C" {
#include<avformat/avformat.h>
#include<avformat/...whatever....h>
}

在文件 demux.cpp 和 codec.cpp 中也是如此。

编辑

尝试按照你的方法做,效果很好。以下是我所做的:

$ cat av.cpp 
extern "C" {
#include <libavformat/avformat.h>
}
int main(void)
{
  av_register_all();
  return 0;
}
$ g++ av.cpp -lavformat
$ ./a.out 

高血压

答案2

问题是,必须按特定顺序指定 libav 库才能解决所有依赖关系。我能够通过首先不使用其他库进行编译来找到正确的顺序。然后,当编译器抱怨未解析的引用时,我通过谷歌搜索该函数属于哪个库来找到该库。我一直这样做,直到所有依赖关系都得到解决。最终的顺序是

  1. AV格式
  2. 音视频编解码器
  3. AVUTIL
  4. x264
  5. 线程
  6. avresample

使用 g++ 编译代码,我使用了这个命令:

c++ ./main.cpp -L/usr/local/lib -lavformat -lavcodec -lavutil -lz -lx264 -lpthread -lavresample -o output

在 Eclipse 中它应该是这样的: 在此处输入图片描述

相关内容