1

I am trying to compile mruby. This is my first time compiling something from command line. When I run make on the directory, I get this:

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

Buildig on Mac OS X 10.7.3 Is there a step that I am missing? Thanks

ashes999
  • 9,925
  • 16
  • 73
  • 124
0xSina
  • 20,973
  • 34
  • 136
  • 253

3 Answers3

2

This problem was fixed some hours ago. Just get a fresh copy of the trunk.

bovi
  • 36
  • 1
1

In case this might be helpful to anyone, here's a quick tutorial of how to get started with mruby:

As a prerequisite, make sure you have git, a C compiler, and bison. You probably already have these installed.

Clone the mruby source code, in this case I'm going to put it in ~/mruby:

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

In your bash profile, create a variable that points to root of this directory. It will be useful later.

export MRUBY_HOME=~/mruby

Now in the mruby root directory, run make:

cd $MRUBY_HOME && make

mruby has now compiled some things and put it in a build directory. There you will find a library for you to include in your own scripts.

Now let's compile an example script. Name this file 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;
}

To compile this script, we need to specify the mruby library archive that we just compiled and include the mruby include directory which contains the header files:

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

This will create a file called a.out. To specify a specific filename, you can pass a -o option and the name of the file that should be used for the compiled output. Executing our newly compiled program should display as expected:

./a.out
Executing Ruby code from C!
hello world!
Andrew
  • 227,796
  • 193
  • 515
  • 708
  • I tried you ways (but in windows), I got the build, but when I compile the sample program give by you I get this error: error: 'mrb_load_string' was not declared in this scope – programmer Jun 06 '15 at 16:15
1

I got this working for Windows. Though of sharing it, in case people need it :)

I used: Windows OS, mingw compiler, bison (extract the binary and the dependency otherwise you will get a dll not found error) ruby

Set all the bin folder of (mindw, bison and ruby) in the PATH environment variable.

Next, inside of mruby folder run: mingw32-make.exe (This is found in the Bin folder of your mingw).

If all the PATH variables were set correctly, your code should compile.

Now you should see the .\build\host\bin with the executable and .\build\host\lib with the required library.

Next create a C++ program ( I used 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 example did not work for me. I was getting an error: 'mrb_load_string' was not declared in this scope

I corrected the error by including: #include

I hope this is quite usefull to setup the lib for windows!

programmer
  • 582
  • 2
  • 4
  • 16