0

我一直在尝试将 mruby 设置为在 C 中使用,但我只成功编译了一个简单的“hello world”示例。其他示例无法编译:当我尝试编译https://github.com/mruby/mruby/blob/master/tools/mrbc/mrbc.c时,我得到了这个:

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) {

当我尝试以他们建议的方式(gcc -Iinclude hello.c lib/libmruby.a -lm -o hello.out(实际上:在类似的方式。我已经尝试了两种方式。)我明白了:

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));
                                     ^

看起来我缺少一些文件或其他东西,但我不确定是什么。我正在使用 mruby 1.1.0。我有 mruby-1.1.0/include,其中包含 mrbconf.h、mruby.h 和 gcc 搜索路径中的文件夹 mruby,以及 LIBRARY_PATH 中的 mruby-1.1.0/build/host/lib(即使在我的示例中)出了什么问题,我只是将它们放在与我正在编译的文件夹相同的文件夹中)。

知道我的安装和/或我的编译方式有什么问题吗?

4

1 回答 1

2

您正在尝试使用较mrbc.c旧版本的 mruby 编译较新版本。这些#defines 是在 1.1.0 发布后添加的。如果我使用 git repo 中当前的 mruby 版本,它对我有用:

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

至于第二个问题,在 July 2012 中mrb_parse_string已更改为接受 anmrb_context*作为第三个参数,因此您可能需要考虑更新代码以使用新 API。

于 2015-04-02T17:33:32.660 回答