Compiling multiple C source files into a single library

In the past I've always put all my code into a single source file and
built it that way. However, I'd like to split out my C source files
into a "one class per file" arrangement for a particular project, but
I'm not sure how to do it. I'm using rake-compiler on Snow Leopard,
btw.

Call Init_bar() from Init_foo(). Ruby will only call one function when
your extension loads. The "Init_*" function maps to the name of the
shared object you build. So if you build "foo.bundle", ruby will call
"Init_foo", and only "Init_foo". Other initialization is up to you.
> // bar.c
> #include <ruby.h>
>
> // I also tried Init_foo here, but that lead to a compiler error
> void Init_bar(){
> VALUE cBar = rb_define_class("Bar", rb_cObject);
> rb_define_const(cBar, "VERSION", rb_str_new2("0.0.1"));
> }
>
> The extconf.rb file is just "require 'mkmf'; create_makefile('foo')".

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!