0

I've been trying to get mruby set up for use in C, but I've only had success compiling a simple "hello world" example. Other examples won't compile: when I try to compile https://github.com/mruby/mruby/blob/master/tools/mrbc/mrbc.c, I get this:

gcc -Iinclude hello.c libmruby_core.a libmruby.a -lm -o hello
hello.c: In function ‘parse_args’:
hello.c:119:24: error: ‘DUMP_DEBUG_INFO’ undeclared (first use in this function)
         args->flags |= DUMP_DEBUG_INFO;
                        ^
hello.c:119:24: note: each undeclared identifier is reported only once for each function it appears in
hello.c:122:23: error: ‘DUMP_ENDIAN_BIG’ undeclared (first use in this function)
         args->flags = DUMP_ENDIAN_BIG | (args->flags & DUMP_DEBUG_INFO);
                       ^
hello.c:125:23: error: ‘DUMP_ENDIAN_LIL’ undeclared (first use in this function)
         args->flags = DUMP_ENDIAN_LIL | (args->flags & DUMP_DEBUG_INFO);
                       ^
hello.c:154:57: error: ‘DUMP_ENDIAN_MASK’ undeclared (first use in this function)
   if (args->verbose && args->initname && (args->flags & DUMP_ENDIAN_MASK) == 0) {

When I try to compile the 'more complex example' from http://matt.aimonetti.net/posts/2012/04/25/getting-started-with-mruby/, in the way they suggest (gcc -Iinclude hello.c lib/libmruby.a -lm -o hello.out) (actually: in a similar way. I've tried both ways.) I get this:

gcc -Iinclude hello.c libmruby.a -lm -o hellohello.c: In function ‘main’:
hello.c:17:7: error: too few arguments to function ‘mrb_parse_string’
   p = mrb_parse_string(mrb, code);
       ^
In file included from /home/neo/Projects/MrubyHs/mruby-1.1.0/include/mruby/irep.h:14:0,
                 from /home/neo/Projects/MrubyHs/mruby-1.1.0/include/mruby/proc.h:10,
                 from hello.c:6:
/home/neo/Projects/MrubyHs/mruby-1.1.0/include/mruby/compile.h:170:34: note: declared here
 MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*);
                                  ^
hello.c:19:5: warning: assignment makes integer from pointer without a cast
   n = mrb_generate_code(mrb, p);
     ^
hello.c:20:37: error: ‘mrb_state’ has no member named ‘irep’
   mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
                                     ^

Looks like I'm missing some file or something, but I'm not sure what. I'm using mruby 1.1.0. I have mruby-1.1.0/include which contains mrbconf.h, mruby.h, and a folder mruby in the gcc search path, and mruby-1.1.0/build/host/lib in LIBRARY_PATH (even though in my examples of what went wrong I just put them in the same folder as where I'm compiling).

Any idea what's wrong with my installation and/or how I'm compiling?

guy0001
  • 35
  • 1
  • 4

1 Answers1

2

You are trying to compile a newer version of mrbc.c with an older version of mruby. Those #defines were added after 1.1.0 was released. It works for me if I use the version of mruby currently in the git repo:

$ make
...
$ gcc -Iinclude build/host/lib/libmruby.a mrbc.c
$ ./a.out
./a.out: no program file given

As for the second problem, mrb_parse_string was changed to accept an mrb_context* as the third argument in July 2012, so you may want to look into updating your code to use the new API.

Dogbert
  • 212,659
  • 41
  • 396
  • 397
  • Now I get something else (this is with the most recent from Github and also with the mrbc that it comes with): http://pastebin.com/3i3nCXaC I also built it just with "make" – guy0001 Apr 02 '15 at 18:50
  • Update: I'm pretty sure everything's installed properly; all the tests ran fine. Still want to know why I can't compile these, but I'm sure it's just because I didn't do my homework: I'll figure it out. Probably should be using the included "rakefile". Don't want to waste anybody's time. Thanks a lot though. – guy0001 Apr 02 '15 at 18:58
  • Does `nm ` print the names of those symbols? – Dogbert Apr 02 '15 at 19:30
  • Yep, they're all in there – guy0001 Apr 02 '15 at 19:43