在Windows 11上通过RubyGems安装wdm 0.1.1时遇错误
安装wdm ~>0.1.1时原生扩展编译失败问题(Windows 11 + Ruby 3.3.0 + gem 3.5.11)
我在Windows 11系统中使用gem 3.5.11安装wdm ~>0.1.1时出现以下错误:
Using rubygems directory: C:/Users/willi/.local/share/gem/ruby/3.3.0 Temporarily enhancing PATH for MSYS/MINGW... Building native extensions. This could take a while... ERROR: Error installing wdm: ERROR: Failed to build gem native extension. current directory: C:/Users/willi/.local/share/gem/ruby/3.3.0/gems/wdm-0.1.1/ext/wdm D:/Chocolatey/lib/ruby.install/tools/True/bin/ruby.exe extconf.rb checking for -lkernel32... yes checking for windows.h... yes checking for ruby.h... yes checking for HAVE_RUBY_ENCODING_H... yes checking for rb_thread_call_without_gvl()... yes creating Makefile current directory: C:/Users/willi/.local/share/gem/ruby/3.3.0/gems/wdm-0.1.1/ext/wdm make DESTDIR\= sitearchdir\=./.gem.20240628-26536-1pbxw8 sitelibdir\=./.gem.20240628-26536-1pbxw8 clean current directory: C:/Users/willi/.local/share/gem/ruby/3.3.0/gems/wdm-0.1.1/ext/wdm make DESTDIR\= sitearchdir\=./.gem.20240628-26536-1pbxw8 sitelibdir\=./.gem.20240628-26536-1pbxw8 generating wdm_ext-x64-mingw-ucrt.def compiling entry.c compiling memory.c compiling monitor.c compiling queue.c compiling rb_change.c rb_change.c: In function 'extract_absolute_path_from_notification': rb_change.c:139:5: warning: 'RB_OBJ_TAINT' is deprecated: taintedness turned out to be a wrong idea. [-Wdeprecated-declarations] 139 | OBJ_TAINT(path); | ^~~~~~~~~ In file included from D:/Chocolatey/lib/ruby.install/tools/True/include/ruby-3.3.0/ruby/internal/core/rstring.h:30, from D:/Chocolatey/lib/ruby.install/tools/True/include/ruby-3.3.0/ruby/internal/arithmetic/char.h:29, from D:/Chocolatey/lib/ruby.install/tools/True/include/ruby-3.3.0/ruby/internal/arithmetic.h:24, from D:/Chocolatey/lib/ruby.install/tools/True/include/ruby-3.3.0/ruby/ruby.h:28, from D:/Chocolatey/lib/ruby.install/tools/True/include/ruby-3.3.0/ruby.h:38, from wdm.h:22, from rb_change.c:4: D:/Chocolatey/lib/ruby.install/tools/True/include/ruby-3.3.0/ruby/internal/fl_type.h:824:1: note: declared here 824 | RB_OBJ_TAINT(VALUE obj) | ^~~~~~~~~~~~ compiling rb_monitor.c rb_monitor.c: In function 'rb_monitor_run_bang': rb_monitor.c:509:29: error: implicit declaration of function 'rb_thread_call_without_gvl' [-Wimplicit-function-declaration] 509 | waiting_succeeded = rb_thread_call_without_gvl(wait_for_changes, monitor->process_event, stop_monitoring, monitor); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ make: *** [Makefile:248: rb_monitor.o] Error 1 make failed, exit code 2 Gem files will remain installed in C:/Users/willi/.local/share/gem/ruby/3.3.0/gems/wdm-0.1.1 for inspection. Results logged to C:/Users/willi/.local/share/gem/ruby/3.3.0/extensions/x64-mingw-ucrt/3.3.0/wdm-0.1.1/gem_make.out
我已尝试以下操作但均无效:
- 重新安装带Devkit的RubyGem
- 在C盘正确安装MSYS64
- 执行
ridk install命令 - 以管理员模式安装
核心原因
wdm 0.1.1是2013年发布的老旧版本,完全不兼容Ruby 3.3.0的API变更——rb_thread_call_without_gvl函数的声明方式在Ruby 3.x中已调整,导致编译时出现隐式声明错误。
解决方法
方法1:安装wdm兼容新版本
放弃指定~>0.1.1版本,直接安装适配Ruby 3.x的最新版:
gem install wdm
如果是Gemfile依赖,修改为:
gem 'wdm'
当前最新稳定版已完美支持Ruby 3.0及以上版本,包括3.3.x。
方法2:回退Ruby版本到兼容旧版
如果必须使用wdm 0.1.1,需要把Ruby版本回退到2.7.x或更早(wdm 0.1.1仅兼容Ruby 2.x系列),用Chocolatey安装示例:
choco install ruby --version=2.7.8
安装完成后执行ridk install配置Devkit,再尝试安装wdm ~>0.1.1。
方法3:手动修复源码(临时方案,不推荐)
一定要在Ruby 3.3.0上使用wdm 0.1.1的话,可手动修改源码:
- 进入gem源码目录:
C:/Users/willi/.local/share/gem/ruby/3.3.0/gems/wdm-0.1.1/ext/wdm - 编辑
rb_monitor.c,在文件开头添加头文件引用:
#include <ruby/thread.h>
- 重新编译安装:
cd C:/Users/willi/.local/share/gem/ruby/3.3.0/gems/wdm-0.1.1/ext/wdm make make install
这个方法只是临时修复,后续gem更新会失效,不建议长期使用。
内容的提问来源于stack exchange,提问作者Idad Wind
相关产品推荐
相关产品推荐

