From: takeru sasaki Date: 2008-10-12T16:25:16+09:00 Subject: [ruby-list:45545] 自作のプログラムにrubyをstaticに組み込みたい 佐々木と申します。 自作のプログラムにrubyをstaticに組み込みたいと思っているのですが、 わからないことがあるので教えてください。 http://eto.com/d/EmbedRuby.html このページからたどっていき、libruby-static.aをリンクして 簡単な計算や文字列処理などは動作させるところまではできたのですが、 拡張ライブラリをどのように組み込むべきなのかがわかりません。 --with-static-linked-ext --disable-shared ext/Setupのoption nodynamic これらのオプションを付ければlibruby-static.aに拡張ライブラリも含めて入って、 libruby-static.aを自作ライブラリにリンクすれば良いのかと思ったのですが 正しいでしょうか? これらのオプションを指定すると何が起こるのかが説明されているドキュメントは ありますか? よろしくお願いします。 以下やったことです。 ■ruby(1.8のtrunk)のビルド 自作プログラムがわにすべて埋め込みたいので、 ./configure --with-static-linked-ext --disable-shared --disable-install-doc --prefix=/Users/takeru/my/ruby18_c として、ext/Setupは ---- option nodynamic enumerator socket stringio thread (#の行は省略しました) ---- として、makeしました。 ■自作プログラムのビルド test1.c ---- #include "ruby.h" int main() { int state = 0; ruby_init(); ruby_init_loadpath(); rb_eval_string("puts 'this is a ' + 'dest program.'.sub(/d/, 't')"); rb_eval_string_protect("puts (1+2+3+4+5).to_s", &state); printf("state=%d\n", state); printf("------------------\n"); //rb_eval_string_protect("puts require('thread')", NULL); rb_eval_string("puts require('thread')"); ruby_stop(0); return 0; } ---- Makefile ---- CC = /usr/bin/gcc-4.0 CFLAGS = -O2 -fno-common -pipe -fno-common -I/opt/local/lib/ruby/1.8/i686-darwin8.11.1 LIBS = -lpthread -ldl -lobjc #LIBRUBYARG = -lruby LIBRUBYARG = /path_to_ruby/libruby-static.a \ /path_to_ruby/ext/thread/thread.o PROGRAM = test1 OBJS = test1.o .c.o: $(CC) $(CFLAGS) -c $< all: $(PROGRAM) clean: rm -f $(PROGRAM) $(OBJS) $(PROGRAM): $(OBJS) $(CC) $(OBJS) $(LIBRUBYARG) $(LIBS) -o $@ ---- makeの出力 /usr/bin/gcc-4.0 -O2 -fno-common -pipe -fno-common -I/opt/local/lib/ruby/1.8/i686-darwin8.11.1 -c test1.c /usr/bin/gcc-4.0 test1.o /path_to_ruby/libruby-static.a /path_to_ruby/ext/thread/thread.o -lpthread -ldl -lobjc -o test1 ./test1の出力 ---- this is a test program. 15 state=0 ------------------ (eval): (eval):0:in `require': no such file to load -- thread (LoadError) from (eval):0 (eval): [BUG] Bus Error ruby 1.8.7 (2008-10-11 revision 19756) [i386-darwin8.11.1] zsh: abort ./test1 -----