4 votes

erreurs lors de la compilation du code c avec la bibliothèque ffmpeg

J'ai installé la bibliothèque ffmpeg dans mon nouvel OS ubuntu 16.04. Lorsque j'ai essayé de compiler mon code c, j'ai obtenu les erreurs étranges suivantes :

/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

J'ai réinstallé la bibliothèque ffmpeg plusieurs fois en utilisant les configurations suivantes :

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

Le processus d'installation s'est déroulé avec succès à chaque fois. Mais lorsque j'ai essayé de compiler mon propre code c, j'ai toujours rencontré les mêmes erreurs que celles mentionnées ci-dessus. Je n'ai aucune idée de ce qui se passe... Voici le makefile que j'ai utilisé :

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 :

Après avoir remplacé $(LIBS) et $(LDLIBS) par $(LDLIBS) $(LIBS) à la ligne 30, le résultat est bien meilleur, mais le compilateur signale toujours les erreurs suivantes :

/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'

Je n'ai aucune idée de la bibliothèque qui manque encore ? Il semble que libva soit toujours manquante.... J'ai trouvé la réponse tout seul... Regardez ici : erreurs de "vaGetDisplay" et "vaGetDisplayDRM".

6voto

Josh de Kock Points 638

Vous devez établir un lien avec les bibliothèques qui fournissent ces fonctions ainsi qu'avec FFmpeg.

Les drapeaux de linker que vous devez ajouter sont (avec leurs erreurs respectives) :

-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'

Ces drapeaux doivent être ajoutés après votre -lav* drapeaux de liaison.


Edit : OP a ajouté le makefile

Vous pouvez également utiliser pkg-config pour toutes les bibliothèques.

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)

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X