0

I’m trying to run a block of Ruby code inside a C program.

I have the following code:

#include <ruby.h>

int main(int argc, char* argv[])
{
    /* Construct the VM */
    ruby_init();

    /* Ruby goes here */

    /* Destruct the VM */
    return ruby_cleanup(0);
}

But when I try to run the program, I get the following error:

fatal error: ruby.h: No such file or directory

#include <ruby.h>

I read that it is needed to tell the compiler about the include paths for the required headers with the following code in Ubuntu:

pkg-config --cflags --libs ruby-2.5

gcc -I/usr/include/ruby-2.5.0 -I/usr/include/ruby-2.5.0/x86_64-linux -lruby

I have already done that, but the problem isn’t solved.

Here is the link: https://silverhammermba.github.io/emberb/embed/

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Erick Pro
  • 33
  • 5
  • 1
    Did you check that directory actually contains a `ruby.h`? /Did you install the needed packages? Could your system have a different version of Ruby? – Fire Lancer Dec 14 '19 at 00:35
  • 1
    You're trying to *compile* the program, not *run* it. At the link you gave, it says, *You will probably need to tell your compiler about the include paths for these headers. You will also need to link with the Ruby lib. **On my machine**, my minimal compiler options ...* The author evidently installed the ruby headers under `/usr/include/ruby-2.5.0` and the library file under `/usr/include/ruby-2.5.0/x86_64-linux`. – lurker Dec 14 '19 at 00:56
  • It's a poorly written website, so it's hard to tell how one is supposed to get the files and put them in their proper locations. But if you read the comments, the first one says you need to install the development version of ruby. Did you do that? – lurker Dec 14 '19 at 00:59

1 Answers1

1

Follow the steps in How can I include a needed C library using GCC?.

I don't understand the difference between the two -l, but try to follow the following structure. If I'm right, your command will be like:

gcc -I/usr/include/ruby-2.5.0 -L/usr/include/ruby-2.5.0/x86_64-linux -lruby

Where:

-I <searchpath to include files>
-L <searchpath to the lib file>
-l <thelibname>

I don't know if the library is the first or the second parameter, but you can check it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1garo
  • 11
  • 2