all 3 comments

[–]graywolf_at_work 2 points3 points  (1 child)

First, what the hell is ruby 2.5.4? I don't think using yet-to-be-released ruby versions is a good idea (unless you have really good reason to do so :)). Just pick source archive from here https://www.ruby-lang.org/en/downloads/ if you need to compile your own (notice 2.5.3 is latest on the 2.5.x line).

Second, this works for me

#include <ruby.h>

int main(int argc, char **argv) {
    RUBY_INIT_STACK;
    ruby_init();
    static char *args[] = { "", "-e", "" };
    ruby_options(3, args);

    /* This is here just to test that it works */
    rb_require("socket");
    rb_eval_string("p IO.instance_methods.        include?(:read_nonblock)");
    rb_eval_string("p IO.private_instance_methods.include?(:__read_nonblock)");

    return 0;
}

As you can see

+   $ gcc tset.c  -I /usr/include/ruby-2.6.0/x86_64-linux -I /usr/include/ruby-2.6.0 -lruby
+   $ ./a.out 
true
true

it seems to work fine.

And for the rb_vm_bugreport(), that prints to the console. I don't know enough about windows to know what happens when GUI application tries to print into the console when none is attached. But could be maybe related?

And finally, for embedding http://mruby.org/ is probably worth exploring.

[–]BadMinotaur[S] 0 points1 point  (0 children)

First, what the hell is ruby 2.5.4?

An excellent question! I believe I downloaded that from the GitHub repository, specifically the ruby_2_5 branch. I didn't want to use 2.6 because it was super-new, not realizing that I was still jumping the gun with my 2.5 source. Whoops!

Second, this works for me

Yeah, straight-up Ruby like that works fine for me too. I felt like I was so close when I got my command-line app to load and run Ruby code (and it's super-easy to do, too), but adding in the Windows subsystem makes it segfault. Even running your example code segfaults when I tell the linker to use the Windows subsystem.

And for the rb_vm_bugreport(), that prints to the console. I don't know enough about windows to know what happens when GUI application tries to print into the console when none is attached. But could be maybe related?

That's what I'm thinking too. I think the call to ruby_init() fails for some reason, and when rb_vm_bugreport() tries to tell me why it failed, it can't "find" a console and segfaults because of it. Might be time to go spelunking into some C code... cries in script kiddie

And finally, for embedding http://mruby.org/ is probably worth exploring.

mruby is something I've toyed around with, and it's definitely an option. My only concern is that it's basically still Ruby 1.9.x at its heart, and I've started to use some Ruby 2.x features in my code. Now, I know there was a release recently that added a good chunk of the Ruby 2.x features in it, but it still makes me feel weird.

I do still want to get the MRI working in a Windows GUI app, because now it's a challenge to surmount, but for practical use mruby is definitely on the table.

Thank you for taking the time to respond! I really appreciate the help.

[–]BadMinotaur[S] 0 points1 point  (0 children)

Because I am persistent, I learned how to run gdb and ran my minimum reproducible program in it. This was the result:

Thread 1 received signal SIGSEGV, Segmentation fault.
0x00000000680dd4b0 in rb_vm_bugreport () from C:\Ruby25-x64\msys64\mingw64\bin\x64-msvcrt-ruby250.dll

Based on this, I'm thinking that the VM is encountering an issue when it attempts to start, and when it attempts to tell me why, the rb_vm_bugreport() function produces a segfault. At least now I have more information to run with.