Search code examples
cstaticcompilationmruby

Minimal static compilation in mruby


I have a simple example:

#include "mruby.h"
#include <mruby/compile.h>

int main() 
{
    mrb_int i; 
    mrb_value c;
    mrb_state *mrb = mrb_open();
    char kod[] = "def suma(a,b) (a+b).to_i end";

    if (!mrb) { /* problemy */ } 
    mrb_load_string(mrb, kod);

    for(i=0; i<9; i++) 
    { 
        c = mrb_funcall(mrb, mrb_top_self(mrb), "suma",  2,
                mrb_fixnum_value(i), mrb_fixnum_value(i)); 
    }
    mrb_close(mrb);
return 0;
}

How can I compile it in static mode, without the library libmruby.a? I only want to add /src/*.c file(s).

I don't need Array. No file access, no other gems (time, test, sprintf, random, etc.)

Which files are important and which can I pass by? I do not need the gem compiler. I can run only bytecode if it is possible.

How can I do this?


Solution

  • You must run rake in the mruby source directory. You will have produce libmruby.a in the build/host/lib directory. (in a specyfic architecture)

    Next you compile your program with -I option and you link your program with -lmruby specified to the linker.

    Is no possible making normal static like as lua