使用 rbenv/ruby-build 安装后如何包含 mruby?

How to include mruby after installing with rbenv/ruby-build?

我正在尝试编译来自 this tutorial 的 "Source Code (.c)" 示例。

我已经使用 rbenv 安装了 mruby:rbenv install mruby-1.2.0

我在尝试编译程序时遇到错误:

$ gcc -std=c99 -Imruby/include test_program.c -o test_program

test_program.c:1:10: fatal error: 'mruby.h' file not found
#include "mruby.h"
         ^
1 error generated.

通过 rbenv/ruby-build 安装时我应该如何引用 mruby 库?

添加-lm

in mruby is /include directory in my source is possible -I mruby_directory/include

接下来添加~/mruby/build/host/lib/libmruby.a

好像rbenv install mruby-1.2.0没有安装mruby的头文件(它只是mruby构建后build/host目录的转储):

% ls $(rbenv prefix mruby-1.2.0)
LEGAL   bin     lib     mrbgems mrblib  src

你需要

# get mruby's code
git clone https://github.com/mruby/mruby.git mruby
# build mruby
cd mruby && rake
# go back to directory of `test_program.c`
cd ..

test_program.c 的编译之前。 你还需要 mruby/build/host/lib/libmruby.a -lm 编译选项。