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

Windows mingw64下Ruby C API的rb_require等函数调用崩溃问题

Ruby C扩展在MinGW64下调用rb_require/rb_marshal_load触发段错误

问题现象

  • 已成功链接Ruby库,rb_eval_string_protect()、rb_file_open()等函数可正常运行,但调用rb_require()加载文件或rb_marshal_load()时触发段错误。
  • 相同代码在MSYS2终端(使用ruby包)编译可正常运行,但MinGW64终端编译会崩溃。
  • 尝试过RubyInstaller库及自行编译Ruby源码,均无法解决问题,仅MSYS2包可部分正常工作。

环境信息

  • 运行环境:MinGW64
  • Ruby库来源:mingw-w64-x86_64-ruby包
  • Ruby版本:3.1.3p185 (2022-11-24 revision 1a6b16756e) [x64-mingw32]

示例代码

ruby_init();
ruby_init_loadpath();
ruby_script("XXX");

const char* load_path = "path/to/rb/file";
rb_require(load_path);

错误回溯信息

ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x64-mingw32]

-- Control frame information -----------------------------------------------
c:0002 p:---- s:0006 e:000005 CFUNC  :getbyte
c:0001 p:0000 s:0003 E:0025c0 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
XXX:0:in `getbyte'

-- C level backtrace information -------------------------------------------
C:\WINDOWS\SYSTEM32\ntdll.dll(ZwWaitForSingleObject+0x14) [0x00007ffb0aa8d0e4]
C:\WINDOWS\System32\KERNELBASE.dll(WaitForSingleObjectEx+0x8e) [0x00007ffb08492d1e]
C:\msys64\mingw64\bin\x64-msvcrt-ruby310.dll(rb_vm_bugreport+0x216) [0x00007ffaaaac95a6]
C:\msys64\mingw64\bin\x64-msvcrt-ruby310.dll(rb_bug_for_fatal_signal+0x84) [0x00007ffaaa91bc14]
C:\msys64\mingw64\bin\x64-msvcrt-ruby310.dll(rb_fiber_scheduler_address_resolve+0x1eb) [0x00007ffaaaa3cf7b]
 [0x00007ff762125ac2]
C:\WINDOWS\SYSTEM32\ntdll.dll(_C_specific_handler+0x96) [0x00007ffb0aa7c876]
C:\WINDOWS\SYSTEM32\ntdll.dll(_chkstk+0x11f) [0x00007ffb0aa923df]
C:\WINDOWS\SYSTEM32\ntdll.dll(RtlRaiseException+0x434) [0x00007ffb0aa414a4]
C:\WINDOWS\SYSTEM32\ntdll.dll(KiUserExceptionDispatcher+0x2e) [0x00007ffb0aa90f0e]
C:\WINDOWS\SYSTEM32\ntdll.dll(RtlWaitOnAddress+0xc6) [0x00007ffb0aa53526]
C:\WINDOWS\SYSTEM32\ntdll.dll(RtlEnterCriticalSection+0x214) [0x00007ffb0aa1fcb4]
C:\WINDOWS\SYSTEM32\ntdll.dll(RtlEnterCriticalSection+0x42) [0x00007ffb0aa1fae2]
C:\msys64\mingw64\bin\x64-msvcrt-ruby310.dll(rb_w32_io_cancelable_p+0x3c) [0x00007ffaaaad748c]
C:\msys64\mingw64\bin\x64-msvcrt-ruby310.dll(rb_io_getbyte+0xd8) [0x00007ffaaa95dcc8]
C:\msys64\mingw64\bin\x64-msvcrt-ruby310.dll(rb_vm_invoke_proc+0x242) [0x00007ffaaaab57f2]
C:\msys64\mingw64\bin\x64-msvcrt-ruby310.dll(rb_eval_cmd_kw+0x5c7) [0x00007ffaaaab7dd7]
C:\msys64\mingw64\bin\x64-msvcrt-ruby310.dll(rb_funcallv+0x11) [0x00007ffaaaab7f11]
C:\msys64\mingw64\bin\x64-msvcrt-ruby310.dll(ruby_init_ext+0x1bc2) [0x00007ffaaa97a7f2]
C:\msys64\mingw64\bin\x64-msvcrt-ruby310.dll(ruby_init_ext+0x52e0) [0x00007ffaaa97df10]
C:\msys64\mingw64\bin\x64-msvcrt-ruby310.dll(rb_protect+0x155) [0x00007ffaaa9256a5]
 [0x00007ff76212176f]
 [0x00007ff7621212ee]
 [0x00007ff762121406]
C:\WINDOWS\System32\KERNEL32.DLL(BaseThreadInitThunk+0x14) [0x00007ffb08eb7604]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 21:10:55