在macOS上执行bundle install时,msgpack gem安装失败
我在MacOS Tahoe(26.3.1(a))。我有一个需要msgpack(1.4.2)的Ruby项目。
很遗憾,当我运行 bundle install 时,看到:
Fetching msgpack 1.4.2
Installing msgpack 1.4.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
[...]
compiling buffer.c
buffer.c:38:16: warning: '(' and '{' tokens introducing statement expression appear in
different macro expansion contexts [-Wcompound-token-split-by-macro]
38 | s_uminus = rb_intern("-@");
| ^~~~~~~~~~~~~~~
[...]
buffer_class.c:261:17: error: incompatible function pointer types passing 'VALUE (VALUE)'
(aka 'unsigned long (unsigned long)') to parameter of type 'VALUE (*)(VALUE, VALUE)' (aka
'unsigned long (*)(unsigned long, unsigned long)') [-Wincompatible-function-pointer-types]
261 | read_until_eof_error, (VALUE)(void*) args,
| ^~~~~~~~~~~~~~~~~~~~
[...]
An error occurred while installing msgpack (1.4.2), and Bundler cannot continue.
完整的错误追踪信息很长,所以我只包含了最相关的信息(如果SO支持 <details> 就好了!)。
解决方案
受到这些 similar questions 的启发,以及 this blog post,我设法通过抑制导致安装出错的特定C 警告来完成这个gem的安装:
gem install msgpack -v 1.4.2 --source 'https://rubygems.org/' -- --with-cflags="-Wno-compound-token-split-by-macro -Wno-incompatible-function-pointer-types"
请注意,上述错误输出中的警告ID是通过 -Wno-* 标志引用的。
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。