extconf.rb Checks compilation conditions and generates a Makefile. For example: require 'mkmf' HEADER_DIRS = [ # ... ] LIB_DIRS = [ # ... ] unless find_header('foo/foo.h', *HEADER_DIRS) abort "libfoo is missing. Please install libfoo" end unless find_library('foo', 'foo_imported_function', *LIB_DIRS) abort "libfoo is missing. Please install libfoo" end create_makefile('foo/foo') See the MakeMakefile documentation for all available checks. 13 / 16
Library initialization and entry point When the interpreter loads the library LIBRARY, it executes the Init_LIBRARY() function. #include #include void Init_foo(void) { VALUE mFoo = rb_define_module("Foo"); rb_define_singleton_method(mFoo, "bar", bar, 1); //... } 14 / 16
Ruby Extension API Used by the library to interact with the Ruby interpreter from the C code. It provides functions to: check data types convert between different types define classes, modules, constants, methods invoke Ruby methods raise exceptions handle allocations and deallocations wrap C pointers into Ruby objects etc. The documentation is in the README.EXT file that comes with the CRuby source code. 15 / 16
Further reading Official documentation about making extension libraries for Ruby: https://github.com/ruby/ruby/blob/trunk/README.EXT Rubygems guide about gems with extensions: http://guides.rubygems.org/gems-with-extensions/ The rake-compiler gem: https://github.com/rake-compiler/rake-compiler Writing Ruby C extensions: http://tenderlovemaking.com/2009/12/18/writing-ruby-c-extensions-part- 1.html http://tenderlovemaking.com/2010/12/11/writing-ruby-c-extensions-part- 2.html Native extensions with Java: https://blog.jcoglan.com/2012/08/02/your-first-ruby-native-extension-java/ 16 / 16