请选择 进入手机版 | 继续访问电脑版

ChinaFFmpeg

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 7819|回复: 3

[Linux] ubuntu16.04调用SDK,测试代码编译异常

[复制链接]
发表于 2019-5-17 11:26:04 | 显示全部楼层 |阅读模式
ffmpeg是使用ffmpeg-3.4.5源码,编译安装成功,lib安装在/usr/local/lib中,include在/usr/local/include中。在ubuntu18.04中,测试代码编译成功;而在ubuntu16.04中,相同安装,测试代码编译报一堆错误,真是怪异,麻烦大家指点指点,谢谢!
说明:代码中exten "C"加了,编译时相应的库-lavformat也加了,
测试代码如下:
extern "C"
{
#include <libavformat/avformat.h>
}
int main(int argc, char **argv)
{
        av_register_all();
        return 0;
}
编译测试代码:g++ -o test test.cpp -lavformat

报错如下:
//usr/local/lib/libavformat.a(allformats.o): In function `register_all':
/home/ffmpeg/ffmpeg-3.4.5/libavformat/allformats.c:47: undefined reference to `avcodec_register_all'
//usr/local/lib/libavformat.a(allformats.o): In function `av_register_all':
/home/ffmpeg/ffmpeg-3.4.5/libavformat/allformats.c:394: undefined reference to `pthread_once'
//usr/local/lib/libavformat.a(amr.o): In function `amr_read_packet':
/home/ffmpeg/ffmpeg-3.4.5/libavformat/amr.c:142: undefined reference to `av_new_packet'
/home/ffmpeg/ffmpeg-3.4.5/libavformat/amr.c:158: undefined reference to `av_packet_unref'
//usr/local/lib/libavformat.a(anm.o): In function `read_header':
/home/ffmpeg/ffmpeg-3.4.5/libavformat/anm.c:136: undefined reference to `av_mallocz'
/home/ffmpeg/ffmpeg-3.4.5/libavformat/anm.c:166: undefined reference to `avpriv_request_sample'
/home/ffmpeg/ffmpeg-3.4.5/libavformat/anm.c:88: undefined reference to `avpriv_request_sample'
//usr/local/lib/libavformat.a(ape.o): In function `ape_read_close':
/home/ffmpeg/ffmpeg-3.4.5/libavformat/ape.c:439: undefined reference to `av_freep'
/home/ffmpeg/ffmpeg-3.4.5/libavformat/ape.c:440: undefined reference to `av_freep'
/home/ffmpeg/ffmpeg-3.4.5/libavformat/ape.c:441: undefined reference to `av_freep'
//usr/local/lib/libavformat.a(ape.o): In function `ape_read_packet':
/home/ffmpeg/ffmpeg-3.4.5/libavformat/ape.c:412: undefined reference to `av_new_packet'
/home/ffmpeg/ffmpeg-3.4.5/libavformat/ape.c:406: undefined reference to `av_log'
/home/ffmpeg/ffmpeg-3.4.5/libavformat/ape.c:419: undefined reference to `av_packet_unref'

后面相同的报错还有很多行......
请问这是为什么?



回复

使用道具 举报

 楼主| 发表于 2019-5-18 18:08:00 | 显示全部楼层
找到了原因了,是在编译ffmpeg的configure时,没有带动态库--enable-shared参数,使用的静态编译,导致出现一堆错误。
在ubuntu18.04系统下test能编译通过,是因为之前安装过apt-get ffmpeg,当然不能通过的ubuntu16.04系统是没有安装;说明这与系统是没关系的。
回复 支持 反对

使用道具 举报

发表于 2019-5-18 18:17:55 | 显示全部楼层
//usr/local/lib/libavformat.a

但是看你的报错信息是提示的这个,.a不是shared,是static,可能是安装的库不太对劲吧
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-5-18 22:22:30 | 显示全部楼层
首先感谢你的回复。
是的,ffmpeg静态编译后,编译出的ffplay是能正常播放视频,就是test demo编译不过去。
看到你的回帖后,我新安装了虚拟系统ubuntu16.04去检验,新装系统避免之前的冲突,如果不带--enable-shared,就是报错。我把报错配置的贴一下:
./configure --extra-libs="-lpthread -lm" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree
如有问题,麻烦指点,谢谢!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|Archiver|ChinaFFmpeg

GMT+8, 2024-3-29 22:07 , Processed in 0.049634 second(s), 14 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表