使用ffmpeg库编译c代码时出错 [英] errors when compiling c code with ffmpeg library

查看:757
本文介绍了使用ffmpeg库编译c代码时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的新ubuntu 16.04操作系统中安装了ffmpeg库。当我尝试编译我的C代码时,我得到以下奇怪的错误:

  / home / broadstand / ffmpeg_build / lib / libavutil .a(hwcontext_vaapi.o):在函数`vaapi_device_free'中:
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:861:未定义的引用到`XCloseDisplay'
/ home / expandingstand / ffmpeg_build / lib / libavutil.a(hwcontext_vaapi.o):在函数`vaapi_device_create'中:
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:891:未定义的引用`XOpenDisplay'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:896:未定义的引用vaGetDisplay
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:903:未定义的引用XDisplayName
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:893:未定义的引用XDisplayName
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:917:未定义的引用到vaGetD isplayDRM'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:891:未定义的引用XOpenDisplay
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:893:未定义的引用XDisplayName
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:898:未定义的引用XDisplayName
/home/widerstand/ffmpeg_build/lib/libavutil.a( hwcontext_vdpau.o):在函数`vdpau_device_create'中:
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:431:未定义的引用XOpenDisplay
/ home / broadstand / ffmpeg_sources / ffmpeg /libavutil/hwcontext_vdpau.c:437:未定义的引用XDisplayString
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:439:未定义的引用XDefaultScreen
/ home / /ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:439:未定义的引用vdp_device_create_x11
/ home / broadstand / ffmpeg_sources / ffmpeg / lib avutil / hwcontext_vdpau.c:433:未定义的引用XDisplayName
/home/widerstand/ffmpeg_build/lib/libavutil.a(hwcontext_vdpau.o):在函数`vdpau_device_free'中:
/ home / expandingstand /ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:410:未定义的引用XCloseDisplay
collect2:错误:ld返回1退出状态
Makefile:30:目标video_analysis的配方失败
make:*** [video_analysis]错误1

我已经重新安装了ffmpeg库多次使用以下配置:

  PATH =$ HOME / bin:$ PATHPKG_CONFIG_PATH =$ HOME / ffmpeg_build / lib / pkgconfig ./configure \ 
--prefix =$ HOME / ffmpeg_build\
--pkg-config-flags = - static\
--extra-cflags = -I $ HOME / ffmpeg_build / include\
--extra-ldflags = - L $ HOME / ffmpeg_build / lib\
--bindir =$ HOME / bin\
--enable-gpl \
--enable-libass \
--enable-li bfdk-aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libtheora \
--enable-libvorbis \
--enable-libvpx \
--enable-libx264 \
--enable-nonfree
PATH =$ HOME / bin:$ PATHmake

安装过程每次都成功。但是当我尝试编译我自己的c代码时,我总是遇到与上述相同的错误。我不知道那个...
这是我使用的makefile:



编辑:

  FFMPEG_LIBS = libavdevice \ 
libavformat \
libavfilter \
libavcodec \
libswresample \\ \\
libswscale \
libavutil \

TARGET = video_analysis
LIBS = -lX11 -lm -lvdpau -lva
CC = gcc
CFLAGS + = -O2 -g -O0
CFLAGS:= $(shell pkg-config --cflags $(FFMPEG_LIBS))$(CFLAGS)
LDLIBS:= $(shell pkg-config - libs $(FFMPEG_LIBS))$(LDLIBS)

.PHONY:默认所有清理

默认值:$(TARGET)
全部:默认

OBJECTS = $(patsubst%.c,%.o,$(通配符* .c))
HEADERS = $(通配符* .h)

% .o:%.c $(HEADERS)
$(CC)$(CFLAGS)-c $< -o $ @

.PRECIOUS:$(TARGET)$(OBJECTS)

$(TARGET):$(OBJECTS)
$(CC)$ OBJECTS)$(LDLIBS)$(LIBS)-o $ @

clean:
-rm -f * .o
-rm -f $(TARGET)

编辑:



Afer在30号交换$(LIBS)和$(LDLIBS)为$(LDLIBS)$(LIBS),看起来好多了,但编译器仍然报告以下错误:

  /root/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o):在函数`vaapi_device_create'中:
/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c: 896:未定义的引用vaGetDisplay
/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:917:未定义的引用vaGetDisplayDRM

我不知道哪个图书馆还缺少?看起来好像libva还是丢失了吗?
我自己得到了答案...看看这里:

您需要链接到提供这些功能的库以及FFmpeg。



您需要添加的链接器标志(及其各自的错误):



-lvdpau - libvdpau-dev

  /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:439:未定义的引用到`vdp_device_create_x11'

-lva - <一个href =https://launchpad.net/ubuntu/+source/libva =noreferrer> libva-dev

  /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:896:undefined re vaGetDisplay
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:917:未定义的引用vaGetDisplayDRM

-lX11 - libx11-dev

  /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:861 :未定义的引用XCloseDisplay
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:898:未定义的引用XDisplayName
/ home / broadstand / ffmpeg_sources / ffmpeg / libavutil / hwcontext_vdpau .c:431:未定义的引用XOpenDisplay
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:437:未定义的引用XDisplayString
/ home / broadstand / ffmpeg_sources / ffmpeg /libavutil/hwcontext_vdpau.c:439:未定义的引用XDefaultScreen

需要添加这些标志在你的 -lav * 链接器之后标志。






编辑:OP添加makefile



也可以使用所有库的pkg-config。

  FFMPEG_LIBS = libavdevice \ 
libavformat \
libavfilter \
libavcodec \
libswresample \
libswscale \
libavutil

PKG_CFG_LIBS = x11 \
vdpau \
libva \
$(FFMPEG_LIBS)

TARGET = video_analysis
LIBS = -lm
CC = gcc
CFLAGS + = -O2 - g -O0
CFLAGS:= $(shell pkg-config --cflags $(PKG_CFG_LIBS))$(CFLAGS)
LDLIBS:= $(shell pkg-config --libs $ (PKG_CFG_LIBS))$(LDLIBS)

.PHONY:默认所有清理

默认值:$(TARGET)
全部:默认

OBJECTS = $(patsubst%.c,%.o,$(通配符* .c))
HEADERS = $(通配符* .h)

%.o:%.c $(HEADERS)
$(CC)$(CFLAGS)-c $< -o $ @

.PRECIOUS:$(TARGET)$(OBJECTS)

$(TARGET):$(OBJECTS)
$(CC)$ OBJECTS)$(LIBS)$(LDLIBS)-o $ @

clean:
-rm -f * .o
-rm -f $(TARGET)


I've installed ffmpeg library in my new ubuntu 16.04 OS. When I tried to compile my c code, I got the following strange errors:

/home/widerstand/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_free':
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:861: undefined reference to `XCloseDisplay'
/home/widerstand/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_create':
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:891: undefined reference to `XOpenDisplay'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:896: undefined reference to `vaGetDisplay'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:903: undefined reference to `XDisplayName'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:893: undefined reference to `XDisplayName'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:917: undefined reference to `vaGetDisplayDRM'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:891: undefined reference to `XOpenDisplay'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:893: undefined reference to `XDisplayName'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:898: undefined reference to `XDisplayName'
/home/widerstand/ffmpeg_build/lib/libavutil.a(hwcontext_vdpau.o): In function `vdpau_device_create':
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:431: undefined reference to `XOpenDisplay'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:437: undefined reference to `XDisplayString'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:439: undefined reference to `XDefaultScreen'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:439: undefined reference to `vdp_device_create_x11'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:433: undefined reference to `XDisplayName'
/home/widerstand/ffmpeg_build/lib/libavutil.a(hwcontext_vdpau.o): In function `vdpau_device_free':
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:410: undefined reference to `XCloseDisplay'
collect2: error: ld returned 1 exit status
Makefile:30: recipe for target 'video_analysis' failed
make: *** [video_analysis] Error 1

I've reinstalled ffmpeg library multiple times using the following configurations:

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-nonfree
PATH="$HOME/bin:$PATH" make

The installation process was successful each time. But when I tried to compile my own c code, I always encountered the same errors as mentioned above. I have no idea about that... Here is the makefile I used:

EDIT:

FFMPEG_LIBS=    libavdevice                        \
                libavformat                        \
                libavfilter                        \
                libavcodec                         \
                libswresample                      \
                libswscale                         \
                libavutil                          \

TARGET = video_analysis
LIBS = -lX11 -lm -lvdpau -lva
CC = gcc
CFLAGS += -O2 -g -O0
CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS)
LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS)

.PHONY: default all clean

default: $(TARGET)
all: default

OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
HEADERS = $(wildcard *.h)

%.o: %.c $(HEADERS)
    $(CC) $(CFLAGS) -c $< -o $@

.PRECIOUS: $(TARGET) $(OBJECTS)

$(TARGET): $(OBJECTS)
    $(CC) $(OBJECTS) $(LDLIBS) $(LIBS) -o $@

clean:
    -rm -f *.o
    -rm -f $(TARGET)

EDIT:

Afer swapping $(LIBS) and $(LDLIBS) to be $(LDLIBS) $(LIBS) at line 30, it looks much better, but the compiler still reports the following errors:

/root/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_create':
/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:896: undefined reference to `vaGetDisplay'
/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:917: undefined reference to `vaGetDisplayDRM'

I have no idea which library is still missing? It looks as if libva were still missing?... I got the answer by myself...Have a look at here: errors of 'vaGetDisplay' and `vaGetDisplayDRM'

解决方案

You need to link with the libraries which provide those functions as well as FFmpeg.

The linker flags you need to add are (with their respective errors):

-lvdpau - libvdpau-dev

/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:439: undefined reference to `vdp_device_create_x11'

-lva - libva-dev

/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:896: undefined reference to `vaGetDisplay'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:917: undefined reference to `vaGetDisplayDRM'

-lX11 - libx11-dev

/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:861: undefined reference to `XCloseDisplay'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:898: undefined reference to `XDisplayName'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:431: undefined reference to `XOpenDisplay'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:437: undefined reference to `XDisplayString'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:439: undefined reference to `XDefaultScreen'

These flags need to be added after your -lav* linker flags.


Edit: OP added makefile

You can also use pkg-config for all the libraries.

FFMPEG_LIBS=    libavdevice                        \
                libavformat                        \
                libavfilter                        \
                libavcodec                         \
                libswresample                      \
                libswscale                         \
                libavutil

PKG_CFG_LIBS=   x11                                \
                vdpau                              \
                libva                              \
                $(FFMPEG_LIBS)

TARGET = video_analysis
LIBS = -lm
CC = gcc
CFLAGS += -O2 -g -O0
CFLAGS := $(shell pkg-config --cflags $(PKG_CFG_LIBS)) $(CFLAGS)
LDLIBS := $(shell pkg-config --libs $(PKG_CFG_LIBS)) $(LDLIBS)

.PHONY: default all clean

default: $(TARGET)
all: default

OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
HEADERS = $(wildcard *.h)

%.o: %.c $(HEADERS)
    $(CC) $(CFLAGS) -c $< -o $@

.PRECIOUS: $(TARGET) $(OBJECTS)

$(TARGET): $(OBJECTS)
    $(CC) $(OBJECTS) $(LIBS) $(LDLIBS) -o $@

clean:
    -rm -f *.o
    -rm -f $(TARGET)

这篇关于使用ffmpeg库编译c代码时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆