首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么有些mruby示例不能编译?

为什么有些mruby示例不能编译?
EN

Stack Overflow用户
提问于 2015-04-03 00:45:06
回答 1查看 168关注 0票数 0

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

代码语言:javascript
复制
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) (实际上:以类似的方式。这两种方法我都试过了。)我明白了:

代码语言:javascript
复制
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中(即使在我的错误示例中,我只是将它们放在与我正在编译的文件夹相同的文件夹中)。

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

EN

回答 1

Stack Overflow用户

发布于 2015-04-03 01:33:33

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

代码语言:javascript
复制
$ 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。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29418165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档