缺少库 arc4random 导致的构建错误

Build error caused by missing library arc4random

我目前正在研究流媒体框架,并决定使用 ffmpeg 来编码和/或解码我的视频和/或音频。

所以我点击 https://ffmpeg.org 找到 api 文件,并下载了静态 linked 版本,结果发现它实际上包含一个 .exe(我使用 Windows 在开发中,但计划在生产中使用 Linux)而不是一个或多个 dll 和 header 信息。

因为我认为我不能使用 'exe' 作为 dll 的替代品,所以我克隆了 git 源代码,并尝试自己编译它。

然后,在编译 i 运行 时出现此错误:

CC  libavutil/random_seed.o
libavutil/random_seed.c: In function 'av_get_random_seed':
libavutil/random_seed.c:130:12: error: implicit declaration of function 'arc4random' [-Werror=implicit-function-declaration]
     return arc4random();
            ^
cc1: some warnings being treated as errors
common.mak:60: recipe for target 'libavutil/random_seed.o' failed
make: *** [libavutil/random_seed.o] Error 1

据我所知,这意味着我缺少库 arc4random,所以我开始搜索这个库,除了这个库在某种程度上与 Apple 相关之外,一无所获...,但没有自己编译的 dll 和东西或源代码。

我使用 cygwin 及其 GCC 在 64 位 windows 7 机器上编译。

任何人都可以提示我可以找到这个丢失的库的某个位置,或者其他可能将 ffmpeg 作为库获取到我的项目中的地方吗? (我更喜欢我可以 link 静态的东西,因为这个项目本身就是一个库)

也许我可以利用下载的 ffmpeg exe,因为我可以从我从 Git 克隆的源中借用它的 headers?

感谢任何提示。

此致,

詹尼克·亚当

这似乎是因为#if错误地报告系统有这个功能。我能够通过编辑几个文件来解决这个问题。

打开 libavutil/random_seed.c 并寻找 #if HAVE_ARC4RANDOM,应该在第 129 行附近,然后删除那三行:

129 #if HAVE_ARC4RANDOM
130     return arc4random();
131 #endif

当你 运行 再次 make 时,你可能会在 time.c 中为 gettimeofday() 遇到另一个类似的失败,所以打开 libavutil/time.c 并寻找 #if HAVE_GETTIMEOFDAY 应该在第 41 行左右并删除那里的第一个块,如下所示:

更改前:

41 #if HAVE_GETTIMEOFDAY
42     struct timeval tv;
43     gettimeofday(&tv, NULL);
44     return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
45 #elif HAVE_GETSYSTEMTIMEASFILETIME

更改后:

41 #if HAVE_GETSYSTEMTIMEASFILETIME

在这两个更改之后,编译得到了更多,但在 ffserver.c:

上失败了
ffserver.c: In function ‘main’:
ffserver.c:4000:5: error: implicit declaration of function ‘sigaction’ [-Werror=implicit-function-declaration]
     sigaction(SIGCHLD, &sigact, 0);

为了修复这个错误,我打开了 config.mak 并在 CFLAGS 的末尾添加了 -D_XOPEN_SOURCE=700,如下所示:

42 CFLAGS=   -std=c99 -fomit-frame-pointer -pthread  -g -Wdeclaration-after-statement -Wall -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -Wmissing-prototypes -Wno-pointer-to-int-cast -Wstrict-prototypes -Wempty-body -Wno-parentheses -Wno-switch -Wno-format-zero-length -Wno-pointer-sign -O3 -fno-math-errno -fno-signed-zeros -Werror=format-security -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=return-type -Werror=vla -Wformat -fdiagnostics-color=auto -Wno-maybe-uninitialized -D_XOPEN_SOURCE=700

This post 解释了为什么 -D_XOPEN_SOURCE=700 有帮助。

然后我又运行make,终于成功了。在 运行ning make install 之后,所有二进制文件都已就位,我能够成功使用它!