提问人:Mohideen Irfan 提问时间:11/2/2023 最后编辑:genpfaultMohideen Irfan 更新时间:11/2/2023 访问量:38
Ffmpeg库编译。(不带 pkg-config) 在 Linux Ubuntu 中
Ffmpeg library compilation .(without pkg-config) in linux ubuntu
问:
我一直在尝试在我的 C 代码中使用 ffmpeg 库。但是当我在 linux 终端中使用 pkg-config 工具编译这些库时,它可以工作。但是当我直接链接所有必要的库时,它将不起作用。我什至在 -L 标志和LD_LIBRARY_PATH中指定了库路径。甚至正确地包含了 -I 标志。但是当我使用 pkg-config 时它可以工作,如果我直接使用它将不起作用。我也导出LD_LIBRARY_PATH。
这是我的 C 程序 Sample.c:
#include <stdio.h>
#include <libavformat/avformat.h>
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Please provide a video file as an argument.\n");
return -1;
}
// av_register_all();
AVFormatContext *pFormatCtx = NULL;
if (avformat_open_input(&pFormatCtx, argv[1], NULL, NULL) != 0) {
printf("Could not open the file.\n");
return -1;
}
if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
printf("Could not find stream information.\n");
return -1;
}
av_dump_format(pFormatCtx, 0, argv[1], 0);
avformat_close_input(&pFormatCtx);
return 0;
}
这是 libavformat.pc 的包文件:
prefix=/home/mohideen-ts205/ffmpeg_build
exec_prefix=${prefix}
libdir=/home/mohideen-ts205/ffmpeg_build/lib
includedir=/home/mohideen-ts205/ffmpeg_build/include
Name: libavformat
Description: FFmpeg container format library
Version: 60.17.100
Requires: libavcodec >= 60.32.102, libswresample >= 4.13.100, libavutil >= 58.30.100
Requires.private:
Conflicts:
Libs: -L${libdir} -lavformat -lm -latomic -lz -lgnutls -pthread -lgmp -lunistring -lidn2 -latomic -lhogweed -lgmp -lnettle -ltasn1 -lp11-kit
Libs.private:
Cflags: -I${includedir}
libavutil.pc:
prefix=/home/mohideen-ts205/ffmpeg_build
exec_prefix=${prefix}
libdir=/home/mohideen-ts205/ffmpeg_build/lib
includedir=/home/mohideen-ts205/ffmpeg_build/include
Name: libavutil
Description: FFmpeg utility library
Version: 58.30.100
Requires:
Requires.private:
Conflicts:
Libs: -L${libdir} -lavutil -pthread -lva-drm -lva -lva-x11 -lva -lvdpau -lX11 -lm -lva -latomic -lX11 -lpthread -lxcb -lXau -lXdmcp
Libs.private:
Cflags: -I${includedir}
这里是命令: 使用 pkg config- 工作一:
gcc -o sample sample.c $(pkg-config --libs libavutil libavformat libavcodec)
没有它直接链接:
gcc -o my_program -I/home/mohideen-ts205/ffmpeg_build/include -L/home/mohideen-ts205/ffmpeg_build/lib -lavformat
注意:我什至尝试复制 libavutil.pc 和 libavformat.pc 中提到的所有库文件,但我仍然收到这个未定义的引用错误。这是什么样的问题。
/usr/bin/ld: /tmp/ccoCfZjA.o: in function `main':
sample.c:(.text+0x63): undefined reference to `avformat_open_input'
/usr/bin/ld: sample.c:(.text+0x8b): undefined reference to `avformat_find_stream_info'
/usr/bin/ld: sample.c:(.text+0xc3): undefined reference to `av_dump_format'
/usr/bin/ld: sample.c:(.text+0xcf): undefined reference to `avformat_close_input'
collect2: error: ld returned 1 exit status
答: 暂无答案
评论