MacOS BigSur下修改brew的libvmaf Formula解决安装报错
解决macOS Big Sur下brew安装libvmaf报
size_t未定义的问题 问题重现
执行brew install libvmaf时,编译阶段触发错误:
Error : unknown type name 'size_t'
该错误发生在Formula执行system "ninja", "-vC", "build"步骤,原因是部分C源码未包含定义size_t的<stddef.h>头文件。手动给对应文件添加头文件后能编译通过,但默认brew会调用原Formula重新拉取源码编译,问题依旧。
自定义Formula修复步骤
1. 创建自定义Formula文件
复制原libvmaf的Formula代码到本地文件(比如~/libvmaf-fixed.rb),并修改install方法,在编译前自动修复头文件缺失问题。
修改后的完整Formula代码:
class Libvmaf < Formula desc "基于多方法融合的感知视频质量评估工具" homepage "https://github.com/Netflix/vmaf" url "https://github.com/Netflix/vmaf/archive/refs/tags/v3.0.0.tar.gz" sha256 "7178c4833639e6b989ecae73131d02f70735fdb3fc2c7d84bc36c9c3461d93b1" license "BSD-2-Clause-Patent" bottle do sha256 cellar: :any, arm64_sonoma: "bdc90ebc175c1f071be4ce895051586583177c3b1029817dc1078472a3da8261" sha256 cellar: :any, arm64_ventura: "cc4765c5f45c5f87bcc42dba73fada9659abbf47bb9adb68bd406c26ac23380a" sha256 cellar: :any, arm64_monterey: "2c9b931ff4d557c6f731b1e834464f96e2620e77f1b857c2ec3061bb589e42da" sha256 cellar: :any, sonoma: "a3ad27257fe552feb0d8ba3f2285feb7a6a772b845514e8d97bf0f9a9c0f1830" sha256 cellar: :any, ventura: "28589a2b48fbd851749f57be19eda359e64056f289f899b80a52224dc3a6ad71" sha256 cellar: :any, monterey: "bb97b9845e37e7090fecfff2e47c32c08c18ea4161da8d88134a7f7be4e07c22" sha256 cellar: :any_skip_relocation, x86_64_linux: "5cb81b38b8c402fc0c12a8a639a7208406958d27a1f8a513c706a5636903cdc4" end depends_on "meson" => :build depends_on "ninja" => :build depends_on "vim" => :build on_intel do depends_on "nasm" => :build end def install Dir.chdir("libvmaf") do # 自动给报错的C文件添加<stddef.h>头文件 inreplace "src/libvmaf.c", /^#include/, "#include <stddef.h>\n#include" inreplace "src/feature/feature.c", /^#include/, "#include <stddef.h>\n#include" system "meson", *std_meson_args, "build" system "ninja", "-vC", "build" system "ninja", "-vC", "build", "install" end pkgshare.install "model" end test do (testpath/"test.c").write <<~EOS #include <libvmaf/libvmaf.h> int main() { return 0; } EOS flags = [ "-I#{HOMEBREW_PREFIX}/include/libvmaf", "-L#{lib}", ] system ENV.cc, "test.c", "-o", "test", *flags system "./test" end end
2. 执行自定义安装
在终端运行以下命令,使用修改后的Formula安装:
brew install ~/libvmaf-fixed.rb
补充说明
- 若编译时还有其他文件报相同错误,只需在
install方法中添加对应的inreplace语句,格式和示例一致 - 这种方式无需手动修改源码打包,直接通过Formula自动完成修复,完全适配brew的安装流程
内容的提问来源于stack exchange,提问作者nathanmacos
相关产品推荐
相关产品推荐

