크리에이티브 커먼즈 라이선스 루비는 그냥 루비고...SWIG란게 뭐냐면 Simplified Wrapper and Interface Generator 라는거라능. C로짠 모듈을 다른 랭귀지에서 불러다 쓸 수 있도록 wrapper랑 interface를 간단하게 만들어 주는 생성기라능. clique흉이 소개해줘서 알게됐는데....일단 루비에다 붙여서 써봤다능.
일단 저기서 받고...configure, make, make install 순서로 설치를 하자능. 리눅스에서는 당근 잘 될태고 난 cygwin에서 돌렸다능. mingw로는 안해봐서 모르겠심.
나도 잘 몰라서 길게는 못쓰겠고 아래 순서로 따라해보면 된다능. 굵은 글씨로 써 있는게 타이핑 해야 될 것이고...more 커맨드로 내용을 출력한 파일들은 직접 만들어 줘야 한다능.
~/swig/test
USER@DMW:> ls
example.c example.i extconf.rb
~/swig/test
USER@DMW:> more example.c
double My_variable = 3.0;
int fact(int n) {
if(n <= 1)
return 1;
else
return n * fact(n-1);
}
int my_mod(int n, int m) {
return n % m;
}
~/swig/test
USER@DMW:> more example.i
%module example
%{
extern double My_variable;
extern int fact(int);
extern int my_nod(int n, int m);
%}
extern double My_variable;
extern int fact(int);
extern int my_mod(int n, int m);
~/swig/test
USER@DMW:> swig -ruby example.i
~/swig/test
USER@DMW:> more extconf.rb
require 'mkmf'
create_makefile('example')
~/swig/test
USER@DMW:> ruby extconf.rb
creating Makefile
~/swig/test
USER@DMW:> make
…….
~/swig/test
USER@DMW:> ls
Makefile example.i example.so* example_wrap.o
example.c example.o example_wrap.c extconf.rb
~/swig/test
USER@DMW:> irb
irb(main):001:0> require 'example'
=> true
irb(main):002:0> Example::fact(5)
=> 120
irb(main):003:0> quit
이제 뭘 더 공부해야 될지는 좀 더 알아봐야겠심. 보면 알겠지만 무지 쉽더라능
요즘에 보내기 페이스북에 보내기 미투데이에 보내기
댓글을 달아 주세요