The include statements presented here corresponds to the values of RbConfig::CONFIG["rubylibdir"]
and RbConfig::CONFIG["rubyarchdir"]'
, so I thought using rbconfig to setup the compilation will give me much better results when compiling on different platforms. I wrote the following Makefile with the prior in mind:
librb = $(shell ruby -e 'puts RbConfig::CONFIG["rubylibdir"]')
arch_dir = $(shell ruby -e 'puts RbConfig::CONFIG["rubyarchdir"]')
CC := gcc -std=c99
EXEC := test
SRCS := src/[a-z]*.c
LIBS := -I$(librb) -I$(arch_dir) -lruby
CFLAGS := -g -Wall -Wextra -Woverflow -Og -pedantic
$(EXEC): $(SRCS)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
Which on my system results in:
gcc -std=c99 -o object_test src/main.c -g -Wall -Wextra -Woverflow -Og -I/home/user/.rbenv/versions/3.2.2/lib/ruby/3.2.0 -I/home/user/.rbenv/versions/3.2.2/lib/ruby/3.2.0/x86_64-linux -lruby
For some reason I still get, “ruby.h: No such file or directory” fatal error, when trying to compile the following code.
#include <ruby.h>
int main(int argc, char* argv[])
{
ruby_init();
//...
return ruby_cleanup(0);
}
I know that my question may seem a duplicate of this one, but the links are broken there and it’s outdated by 13 years. I am most concerned about ruby > 3.1 for my project.