You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows系统安装mailcatcher gem失败问题求助

MailCatcher在Windows更新后安装失败的解决方法

问题描述

Windows更新后,开发用的MailCatcher无法正常启动。更新Ruby后安装MailCatcher时失败,尝试安装测试版0.9.0.beta2仍出现编译错误,具体错误如下:

C:\WINDOWS\system32>gem install mailcatcher --version=0.9.0.beta2
临时提升MSYS/MINGW的PATH环境变量...
正在构建原生扩展,这可能需要一段时间...
ERROR:  安装mailcatcher失败:
        ERROR: 无法构建gem原生扩展。

    当前目录: C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/eventmachine-1.0.9.1/ext/fastfilereader
C:/Ruby32-x64/bin/ruby.exe extconf.rb
创建Makefile

当前目录: C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/eventmachine-1.0.9.1/ext/fastfilereader
make DESTDIR\= sitearchdir\=./.gem.20230621-29048-1p4cu8 sitelibdir\=./.gem.20230621-29048-1p4cu8 clean

当前目录: C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/eventmachine-1.0.9.1/ext/fastfilereader
make DESTDIR\= sitearchdir\=./.gem.20230621-29048-1p4cu8 sitelibdir\=./.gem.20230621-29048-1p4cu8
生成fastfilereaderext-x64-mingw-ucrt.def
编译mapper.cpp
编译rubymain.cpp
In file included from C:/Ruby32-x64/msys64/ucrt64/include/wtypes.h:8,
                 from C:/Ruby32-x64/msys64/ucrt64/include/winscard.h:10,
                 from C:/Ruby32-x64/msys64/ucrt64/include/windows.h:97,
                 from C:/Ruby32-x64/msys64/ucrt64/include/winsock2.h:23,
                 from C:/Ruby32-x64/include/ruby-3.2.0/ruby/win32.h:36,
                 from C:/Ruby32-x64/include/ruby-3.2.0/ruby/internal/dosish.h:38,
                 from C:/Ruby32-x64/include/ruby-3.2.0/ruby/defines.h:78,
                 from C:/Ruby32-x64/include/ruby-3.2.0/ruby/ruby.h:25,
                 from C:/Ruby32-x64/include/ruby-3.2.0/ruby.h:38,
                 from rubymain.cpp:26:
C:/Ruby32-x64/msys64/ucrt64/include/rpcndr.h:64:11: 错误: 'byte'的引用有歧义
   64 |   typedef byte cs_byte;
      |           ^~~~
In file included from C:/Ruby32-x64/msys64/ucrt64/include/c++/13.1.0/bits/memory_resource.h:38,
                 from C:/Ruby32-x64/msys64/ucrt64/include/c++/13.1.0/string:58,
                 from C:/Ruby32-x64/msys64/ucrt64/include/c++/13.1.0/bits/locale_classes.h:40,
                 from C:/Ruby32-x64/msys64/ucrt64/include/c++/13.1.0/bits/ios_base.h:41,
                 from C:/Ruby32-x64/msys64/ucrt64/include/c++/13.1.0/ios:44,
                 from C:/Ruby32-x64/msys64/ucrt64/include/c++/13.1.0/ostream:40,
                 from C:/Ruby32-x64/msys64/ucrt64/include/c++/13.1.0/iostream:41,
                 from rubymain.cpp:22:
C:/Ruby32-x64/msys64/ucrt64/include/c++/13.1.0/cstddef:69:14: 注: 候选为: 'enum class std::byte'
   69 |   enum class byte : unsigned char {};
      |              ^~~~
C:/Ruby32-x64/msys64/ucrt64/include/rpcndr.h:63:25: 注:                 'typedef unsigned char byte'
   63 |   typedef unsigned char byte;
      |                         ^~~~
C:/Ruby32-x64/msys64/ucrt64/include/rpcndr.h:397:170: 错误: 'byte'的引用有歧义
  397 |   typedef void (__RPC_API *CS_TYPE_TO_NETCS_ROUTINE)(RPC_BINDING_HANDLE hBinding,unsigned __LONG32 ulNetworkCodeSet,void *pLocalData,unsigned __LONG32 ulLocalDataLength,byte *pNetworkData,unsigned __LONG32 *pulNetworkDataLength,error_status_t *pStatus);
      |                                                                                                                                                                          ^~~~
C:/Ruby32-x64/msys64/ucrt64/include/rpcndr.h:398:119: 错误: 'byte'的引用有歧义
  398 |   typedef void (__RPC_API *CS_TYPE_FROM_NETCS_ROUTINE)(RPC_BINDING_HANDLE hBinding,unsigned __LONG32 ulNetworkCodeSet,byte *pNetworkData,unsigned __LONG32 ulNetworkDataLength,unsigned __LONG32 ulLocalBufferSize,void *pLocalData,unsigned __LONG32 *pulLocalDataLength,error_status_t *pStatus);
      |                                                                                                                         
 
make: *** [Makefile:240: rubymain.o] 错误 1

make执行失败,退出码2

Gem文件将保留在C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/eventmachine-1.0.9.1供检查。
结果已记录到C:/Ruby32-x64/lib/ruby/gems/3.2.0/extensions/x64-mingw-ucrt/3.2.0/eventmachine-1.0.9.1/gem_make.out

C:\WINDOWS\system32>

错误原因

问题根源在于Ruby 3.2采用了UCRT工具链,而MailCatcher依赖的旧版本eventmachine(1.0.9.1)不兼容该工具链。具体冲突是:C++17标准引入了std::byte枚举类,Windows系统头文件rpcndr.h中又定义了typedef unsigned char byte,两者编译时产生命名歧义,导致原生扩展构建失败。

解决方案

方案1:安装兼容的eventmachine版本

先安装支持UCRT工具链的eventmachine新版本,再安装MailCatcher测试版:

  1. 打开命令提示符,执行:
    gem install eventmachine --version=1.2.7
    
  2. 再安装MailCatcher测试版:
    gem install mailcatcher --version=0.9.0.beta2
    

方案2:降级Ruby版本

如果方案1无效,可将Ruby降级到3.1.x版本(该版本使用MSVCRT工具链,无此命名冲突):

  1. 卸载当前Ruby 3.2.x版本
  2. 从RubyInstaller官网下载Ruby 3.1.x版本并安装
  3. 重新执行gem install mailcatcher --version=0.9.0.beta2

方案3:临时修改eventmachine源码(不推荐)

若需临时应急,可手动修改eventmachine源码:

  1. 找到eventgem安装目录下的rubymain.cpp文件(路径:C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/eventmachine-1.0.9.1/ext/fastfilereader/rubymain.cpp)
  2. 在文件开头添加#define byte win_byte,规避命名冲突
  3. 重新执行安装命令

内容的提问来源于stack exchange,提问作者maidan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 05:24:57