我一直试图让mrub用于C语言,但我只是成功编写了一个简单的“你好世界”#34;例。其他例子不会编译:当我尝试编译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) {
当我尝试编译“更复杂的例子”时来自http://matt.aimonetti.net/posts/2012/04/25/getting-started-with-mruby/,他们建议的方式(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。我有mrubb-1.1.0 / include,其中包含mrbconf.h,mruby.h和gcc搜索路径中的mruby文件夹,以及LIBRARY_PATH中的mruby-1.1.0 / build / host / lib(即使在我的示例中)出了什么问题我把它们放在我正在编译的文件夹中。
知道我的安装有什么问题和/或我是如何编译的?
答案 0 :(得分:2)
您正在尝试使用旧版本的mruby编译较新版本的mrbc.c
。这些#define
已添加after 1.1.0 was released。如果我使用当前在git repo中的mruby版本,它对我有用:
$ make
...
$ gcc -Iinclude build/host/lib/libmruby.a mrbc.c
$ ./a.out
./a.out: no program file given
至于第二个问题,mrb_parse_string
已更改为接受mrb_context*
作为第三个参数in July 2012,因此您可能希望更新代码以使用新API。