【问题标题】:Compiling mruby编译mruby
【发布时间】:2012-05-02 19:08:46
【问题描述】:

我正在尝试编译mruby。这是我第一次从命令行编译一些东西。 当我在目录上运行 make 时,我得到了这个:

make -C mrblib --no-print-directory CC=gcc LL=gcc
make -C ../tools/mrbc --no-print-directory CC=gcc LL=gcc
gcc -Wall -Werror-implicit-function-declaration -g -MMD -I../../src -I../../src/../include -c ../../src/st.c -o ../../src/st.o
In file included from ../../src/regint.h:93,
                 from ../../src/st.c:6:
../../src/../include/mruby.h: In function ‘mrb_special_const_p’:
../../src/../include/mruby.h:100: warning: comparison is always true due to limited range of data type
../../src/st.c: In function ‘st_hash’:
../../src/st.c:1053: error: ‘SIZEOF_ST_INDEX_T’ undeclared (first use in this function)
../../src/st.c:1053: error: (Each undeclared identifier is reported only once
../../src/st.c:1053: error: for each function it appears in.)
make[2]: *** [../../src/st.o] Error 1
make[1]: *** [../bin/mrbc] Error 2
make: *** [src/mrblib/mrblib.o] Error 2

Mac OS X 10.7.3 上的 Buildig 有没有我遗漏的步骤? 谢谢

【问题讨论】:

  • 在构建软件时,重要的是要提及您使用的平台。
  • 哎呀,完全忘记了。我用信息更新了我的问题。

标签: c compilation mruby


【解决方案1】:

此问题已在数小时前修复。只需获取行李箱的新副本即可。

【讨论】:

    【解决方案2】:

    如果这对任何人都有帮助,这里有一个快速教程,介绍如何开始使用 mruby:

    作为先决条件,请确保您拥有 git、C 编译器和 bison。您可能已经安装了这些。

    克隆mruby源代码,本例我将其放入~/mruby

    git clone https://github.com/mruby/mruby.git ~/mruby
    

    在您的 bash 配置文件中,创建一个指向该目录根目录的变量。以后会有用的。

    export MRUBY_HOME=~/mruby
    

    现在在 mruby 根目录下,运行 make:

    cd $MRUBY_HOME && make
    

    mruby 现在已经编译了一些东西并将其放在build 目录中。在那里你会找到一个库供你包含在你自己的脚本中。

    现在让我们编译一个示例脚本。将此文件命名为example.c

    #include <stdlib.h>
    #include <stdio.h>
    #include <mruby.h>
    
    int main(void)
    {
      mrb_state *mrb = mrb_open();
      char code[] = "p 'hello world!'";
      printf("Executing Ruby code from C!\n");
      mrb_load_string(mrb, code);
      return 0;
    }
    

    要编译这个脚本,我们需要指定我们刚刚编译的mruby库存档,并包含包含头文件的mruby包含目录:

    gcc example.c $MRUBY_HOME/build/host/lib/libmruby.a -I $MRUBY_HOME/include
    

    这将创建一个名为a.out 的文件。要指定特定的文件名,您可以传递 -o 选项和应该用于编译输出的文件的名称。执行我们新编译的程序应该会按预期显示:

    ./a.out
    Executing Ruby code from C!
    hello world!
    

    【讨论】:

    • 我尝试了你的方法(但在 Windows 中),我得到了构建,但是当我编译你提供的示例程序时,我得到这个错误:错误:'mrb_load_string' 没有在这个范围内声明
    【解决方案3】:

    我让这个适用于 Windows。虽然分享它,以防人们需要它:)

    我用过: 视窗操作系统, mingw编译器, bison(提取二进制文件和依赖项,否则您将收到 dll not found 错误) 红宝石

    在PATH环境变量中设置(mindw、bison和ruby)的所有bin文件夹。

    接下来,在 mruby 文件夹中运行:mingw32-make.exe(在你的 mingw 的 Bin 文件夹中)。

    如果所有 PATH 变量都设置正确,您的代码应该可以编译。

    现在您应该看到带有可执行文件的 .\build\host\bin 和带有所需库的 .\build\host\lib。

    接下来创建一个 C++ 程序(我使用 C::B)。

    #include <stdlib.h>
    #include <stdio.h>
    #include <mruby.h>
    #include <mruby/compile.h>
    
    int main(void)
    {
      mrb_state *mrb = mrb_open();
      if (!mrb) { /* handle error */ }
      puts("Executing Ruby code from C!");
      mrb_load_string(mrb, "p 'hello world!'");
      mrb_close(mrb);
      return 0;
    }
    

    @Andrew 示例对我不起作用。我收到一个错误:'mrb_load_string' 没有在这个范围内声明

    我纠正了错误,包括:#include

    我希望这对于为 Windows 设置库非常有用!

    【讨论】:

      猜你喜欢
      • 2013-10-20
      • 2017-07-02
      • 2015-03-24
      • 2015-06-07
      • 2016-09-27
      • 2020-03-30
      • 2015-08-21
      • 2018-01-24
      • 2018-05-28
      相关资源
      最近更新 更多