LoginSignup
2
2

More than 5 years have passed since last update.

mruby が変わってた (on Ubuntu)

Posted at

前の投稿 http://qiita.com/items/ad40f5e11e0fafcc0bf7 から 1 ヶ月少々が経過し,最新の mruby を取得してきてビルドしてみようとしたら出来なくなってたので修正を.

まず Hello World のサンプルコードですが,GitHub 上の Wiki にありました.
https://github.com/mruby/mruby/wiki/Hello-World

しかし include ディレクトリの中に compile.h が無いのでコメントの指示通り

hello-world.c
#include <stdlib.h>
#include <stdio.h>

/* Include the mruby header */
#include <mruby.h>
#include <mruby/proc.h>
#include <mruby/data.h>
#include <mruby/compile.h> /* ここが変更された */

int main(void)
{
  struct mrb_parser_state *p;
  mrb_state *mrb = mrb_open();
  char code[] = "p 'hello world!'";
  printf("Executing Ruby code from C!\n");

  p = mrb_parse_string(mrb, code);
  int n;
  n = mrb_generate_code(mrb, p->tree);
  mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
  if (mrb->exc) {
    mrb_p(mrb, mrb_obj_value(mrb->exc));
  }
  return 0;
}

と変更します.後は,hello-world.c を mruby ディレクトリに置いてそこで

gcc -Iinclude hello-world.c lib/libmruby.a -lm

そして

./a.out

すれば

Executing Ruby code from C!
"hello world!"

と表示され Hello World プログラム無事成功です.

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2