errors of 'vaGetDisplay' and `vaGetDisplay

2019-02-27 14:05发布

问题:

This question already has an answer here:

  • errors when compiling c code with ffmpeg library 1 answer

After updating my ubuntu OS from 14.04 to 16.04, I installed the ffmpeg library 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
make install

It seemed to me the installation process was ok. After that, I tried to compile my own C source code with the following Makefile:

EDITTED(adding -lva-drm -lva-x11 at line 10)

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

TARGET = video_analysis
LIBS = -lva -lX11 -lvdpau -lm -lva-drm -lva-x11
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)

However, my compiler complained the following errors:

/root/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_create':
/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'
collect2: error: ld returned 1 exit status
Makefile:30: recipe for target 'video_analysis' failed
make: *** [video_analysis] Error 1

My question is: in which library do 'vaGetDisplay' and `vaGetDisplayDRM' exist? It's for sure that libva functions properly. I have no clue how to fix the bugs...Thank you in advance!

回答1:

I got the exact same problem when I was trying to compile the latest ffmpeg source code examples. (2016-08-25)

When I have done compiling ffmpeg source, (all dependencies good), then I go to dir:

~/ffmpeg_build/share/ffmpeg/examples$

do:

export PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig"

and as instructed as README:

make

I got the C files compiled to .o files but cannot get linked. Same error output as:

jack@jack-virtual-machine:~/ffmpeg_build/share/ffmpeg/examples$ make
cc   avio_reading.o  -pthread -L/home/jack/ffmpeg_build/lib -lavdevice -lavfilter -lpostproc -lavformat -lavcodec -lvdpau -lva-drm -lva-x11 -lva -lxcb-shm -lxcb-xfixes -lxcb-render -lxcb-shape -lxcb -lXau -lXdmcp -lSDL -lasound -lpulse-simple -lpulse -lX11 -lXext -lcaca -lx265 -lstdc++ -lrt -lx264 -ldl -lvpx -lpthread -lvorbisenc -lvorbis -ltheoraenc -ltheoradec -logg -lopus -lmp3lame -lfdk-aac -lass -lharfbuzz -lfontconfig -lfribidi -lexpat -lfreetype -lpng12 -llzma -lbz2 -lz -lswresample -lswscale -lavutil -lm    -o avio_reading
/home/jack/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_free':
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:861: undefined reference to `XCloseDisplay'
/home/jack/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_create':
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:891: undefined reference to `XOpenDisplay'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:896: undefined reference to `vaGetDisplay'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:903: undefined reference to `XDisplayName'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:917: undefined reference to `vaGetDisplayDRM'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:893: undefined reference to `XDisplayName'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:898: undefined reference to `XDisplayName'
/home/jack/ffmpeg_build/lib/libavutil.a(hwcontext_vdpau.o): In function `vdpau_device_create':
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:431: undefined reference to `XOpenDisplay'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:437: undefined reference to `XDisplayString'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:439: undefined reference to `XDefaultScreen'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:439: undefined reference to `vdp_device_create_x11'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:433: undefined reference to `XDisplayName'
/home/jack/ffmpeg_build/lib/libavutil.a(hwcontext_vdpau.o): In function `vdpau_device_free':
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:410: undefined reference to `XCloseDisplay'
collect2: error: ld returned 1 exit status
make: *** [avio_reading] Error 1

I checked your solution here and discovered that although ffmpeg team are using pkg-config tool to config, but in the end it is a gcc command line to compile. (see the seconde line of code snippet above)

All the flags below shall be moved to the end of gcc command line just before the -o option:

-lX11 -lm -lvdpau -lva -lva-drm -lva-x11

So instead of compiling with the next command line:(the command is long, scroll to right to see full)

cc   avio_reading.o  -pthread -L/home/jack/ffmpeg_build/lib -lavdevice -lavfilter -lpostproc -lavformat -lavcodec -lvdpau -lva-drm -lva-x11 -lva -lxcb-shm -lxcb-xfixes -lxcb-render -lxcb-shape -lxcb -lXau -lXdmcp -lSDL -lasound -lpulse-simple -lpulse -lX11 -lXext -lcaca -lx265 -lstdc++ -lrt -lx264 -ldl -lvpx -lpthread -lvorbisenc -lvorbis -ltheoraenc -ltheoradec -logg -lopus -lmp3lame -lfdk-aac -lass -lharfbuzz -lfontconfig -lfribidi -lexpat -lfreetype -lpng12 -llzma -lbz2 -lz -lswresample -lswscale -lavutil -lm    -o avio_reading

I move the flags to the right side end and compile with:(the command is long, scroll to right to see full)

cc   avio_dir_cmd.o  -pthread -L/home/jack/ffmpeg_build/lib -lavdevice -lavfilter -lpostproc -lavformat -lavcodec -lxcb-shm -lxcb-xfixes -lxcb-render -lxcb-shape -lxcb -lXau -lXdmcp -lSDL -lasound -lpulse-simple -lpulse -lXext -lcaca -lx265 -lstdc++ -lrt -lx264 -ldl -lvpx -lpthread -lvorbisenc -lvorbis -ltheoraenc -ltheoradec -logg -lopus -lmp3lame -lfdk-aac -lass -lharfbuzz -lfontconfig -lfribidi -lexpat -lfreetype -lpng12 -llzma -lbz2 -lz -lswresample -lswscale -lavutil  -lX11 -lm  -lvdpau -lva -lva-drm -lva-x11 -o avio_dir_cmd

And all the compile errors are gone~! I think this is a common error when we compile other examples, or our own projects.



回答2:

after adding -lva-drm and -lva-x11 into Makefile, my compiler complains no error any more :-)



标签: c ffmpeg