我一直在尝试将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) {当我试图编译来自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。我有mruby-1.1.0/include,它包含mrbconf.h、mruby.h和一个文件夹mruby,位于gcc搜索路径中,mruby-1.1.0/build/host/lib位于LIBRARY_PATH中(即使在我的错误示例中,我只是将它们放在与我正在编译的文件夹相同的文件夹中)。
你知道我的安装和/或我的编译方式有什么问题吗?
发布于 2015-04-03 01:33:33
您正在尝试使用较旧版本的mrbc.c编译较新版本的mruby。这些#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。
https://stackoverflow.com/questions/29418165
复制相似问题