Embedded Ruby in C can't find external libraries. Help!

I try to embed Ruby in C, and it works fine.
But if there is 'requre" in ruby, it won’t work.
The test source code is here:

#include <ruby.h>

int main()
{
int state;

ruby_init();

rb_eval_string_protect(“require ‘test/unit’\nputs ‘Ruby Test’”, &state);

if (state) {
VALUE c = rb_funcall(rb_gv_get("$!"), rb_intern(“to_s”), 0);
printf(“Error: %s\n”, RSTRING©->ptr);
}

return 0;
}

It will complain “No such file to load – test/unit” (Test::Unit),
which is installed and works fine in normal ruby application.

Did I miss something ?

Thanx a lot.

Yen-Ju

I tried adding “p $:” into your eval, and it shows that $: ($LOAD_PATH) is
set to the empty array.

The solution is to add a call to
ruby_init_loadpath();
after ruby_init()

Regards,

Brian.

···

On Sat, May 03, 2003 at 05:08:30AM +0900, Yen-Ju Chen wrote:

I try to embed Ruby in C, and it works fine.
But if there is 'requre" in ruby, it won’t work.
The test source code is here:

#include <ruby.h>

int main()
{
int state;

ruby_init();

rb_eval_string_protect(“require ‘test/unit’\nputs ‘Ruby Test’”, &state);

if (state) {
VALUE c = rb_funcall(rb_gv_get(“$!”), rb_intern(“to_s”), 0);
printf(“Error: %s\n”, RSTRING(c)->ptr);
}

return 0;
}

It will complain “No such file to load – test/unit” (Test::Unit),
which is installed and works fine in normal ruby application.

Did I miss something ?