Linker 如何在Windows上将程序与ffmpeg静态链接?
几个小时以来,我一直在尝试在Linux上自动工作的方法,现在是在Windows上。我想链接一个程序,但对于这个问题,只有下面列出的带有ffmpeg的简短示例ffmpeg程序 安装程序 目前我在Linux上,使用mingw编译并使用。目录设置如下所示:Linker 如何在Windows上将程序与ffmpeg静态链接?,linker,mingw,Linker,Mingw,几个小时以来,我一直在尝试在Linux上自动工作的方法,现在是在Windows上。我想链接一个程序,但对于这个问题,只有下面列出的带有ffmpeg的简短示例ffmpeg程序 安装程序 目前我在Linux上,使用mingw编译并使用。目录设置如下所示: dumpVideoInfo.c + bin avformat-54.dll avutil-51.dll + lib avcodec.lib avcodec.dll.a avutil.lib avutil.dll.a 问题
dumpVideoInfo.c
+ bin
avformat-54.dll
avutil-51.dll
+ lib
avcodec.lib
avcodec.dll.a
avutil.lib
avutil.dll.a
问题
尝试与.dll文件动态链接会导致无法识别文件格式错误
尝试将其与.lib/.dll.a链接时导致未定义的引用错误:
部分解
正如上面的bin64/lib64目录所暗示的,我使用的是64位库。更改为32位库后,上述错误消失
遗留问题
无论我是链接到bin/还是lib/directory.dll还是.lib/.dll.a,生成的可执行文件都保持23 KB,并且仍然需要.dll文件。如何静态链接程序?
.lib和.dll.a文件之间有什么区别?
密码
谢谢你的回答
$ i586-mingw32msvc-gcc -v -Wall -Iinclude dumpVideoInfo.c -o dumpVideoInfo.exe -L./bin64 -lavformat-54 -lavutil-51
./bin64/avformat-54.dll: file not recognized: File format not recognized
$ i586-mingw32msvc-gcc -v -Wall -Iinclude dumpVideoInfo.c -o dumpVideoInfo.exe -L./lib64 -lavformat -lavutil
/tmp/ccSKJQAc.o:dumpVideoInfo.c:(.text+0x30): undefined reference to `_av_register_all'
/tmp/ccSKJQAc.o:dumpVideoInfo.c:(.text+0x6e): undefined reference to `_avformat_open_input'
/tmp/ccSKJQAc.o:dumpVideoInfo.c:(.text+0xbf): undefined reference to `_avformat_find_stream_info'
/tmp/ccSKJQAc.o:dumpVideoInfo.c:(.text+0xef): undefined reference to `_av_dump_format'
/tmp/ccSKJQAc.o:dumpVideoInfo.c:(.text+0xfe): undefined reference to `_av_free'
#include <stdio.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
int main(int argc, char *argv[])
{
char *filename;
if (argc > 1) {
filename = argv[1];
} else {
printf("No video file given.");
return 2;
}
av_register_all();
AVFormatContext *pFormatContext = NULL;
printf("Reading info for file %s.\n", filename);
fflush(stdout);
int ret;
if ((ret = avformat_open_input(&pFormatContext, filename, NULL, NULL)) != 0) {
printf("Could not open file %s.\n", filename);
return 2;
}
if (avformat_find_stream_info(pFormatContext, NULL) < 0) {
printf("No stream information found.\n");
return 2;
}
av_dump_format(pFormatContext, 0, filename, 0);
av_free(pFormatContext);
return 0;
}