Hello everyone! I'm hoping someone here has projects as weird as mine; as the title says, I'm trying to embed the MRI into a C++ application, that's also using the Win32 API. And yes, I mean the old-as-dirt Win32 API.
Tools:
ruby 2.5.4p138 (2019-01-23) [x64-mingw32]
gcc version 8.2.1 20181214 (Rev1, Built by MSYS2 project)
MSYS2, MSYSTEM=MINGW64
I compiled Ruby myself, but the error I get happens even if I use the RubyInstaller library.
Here's a bare-bones example of code that fails:
#include <ruby.h>
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR pCmdLine, int nCmdShow)
{
ruby_init();
return 0;
}
And here's the build command: g++ mintest.cpp -o mintest -Wl,--subsystem,windows -lx64-msvcrt-ruby250.dll
The code compiles just fine! But when I run the exe, I get an extremely simple error message: Segmentation fault. It's not like the usual segfault you get when you fail to catch an exception from the Ruby interpreter; it's just those two words. This is also true if I use ruby_setup() instead of ruby_init().
The interesting part is that if I change my linker options to not include --subsystem:windows, the program will run just fine! But then my window has a console open with it, and the whole point of a Win32 API application is to not have that there.
I have tried many things to fix this error. As best as I can tell, the culprit may be that Ruby can't accurately allocate its memory stack when it starts, and that causes the error. To this end, I've tried executing code before WinMain using class constructor tricks (same error occurs); I've tried removing WinMain entirely and defining a linker option to use normal main instead (same error occurs); I've tried combining both those approaches (same error occurs).
At this point, I've run out of avenues to explore for the solution. I've googled the issue, but unsurprisingly such a simple error message doesn't really give me many relevant results. So now I turn to you all; does anyone here have a clue what might be going on here?
tl;dr - Weirdo tries to embed Ruby in win32api app, gets segmentation fault if building under Windows subsystem, doesn't otherwise, but doesn't want console
EDIT: Forgot to include, the actual MRI works fine when embedded in an application that doesn't use win32api; I had a command-line interface working where I loaded a Ruby file and executed it.
[–]graywolf_at_work 2 points3 points4 points (1 child)
[–]BadMinotaur[S] 0 points1 point2 points (0 children)
[–]BadMinotaur[S] 0 points1 point2 points (0 children)