Skip to content
Daniel Berger edited this page Mar 28, 2023 · 13 revisions

Overview

The mkmf-lite gem is a lightweight version of the mkmf library that ships as part of the Ruby standard library. Unlike the mkmf library, this library is meant to be used as a module. It is NOT meant as a build tool, nor is it a replacement for mkmf.

Supported Methods

The mkmf-lite module currently includes the following methods:

  • check_sizeof
  • check_valueof
  • have_func
  • have_func_pointer
  • have_header
  • have_struct_member

Example

require 'mkmf/lite'

class System
  extend Mkmf::Lite

  HAVE_PW_NAME = have_struct_member('struct passwd', 'pw_name', 'pwd.h')

  def some_method
    if HAVE_PW_NAME
      # Do something
    end

    if have_func('printf', 'stdio.h')
      # Do something else
    end

    if have_header('stdio.h')
      # Other things
    end
  end
end

Possible Issues

You may see a difference between the results of the methods provided here and the ones from Ruby's mkmf library. How is that possible?

The difference is in the header files that are automatically included when a check is made. Ruby's mkmf library will always use "ruby.h" as an included header file. That header, in turn, includes several other header files whereas this library only uses common header files, or just <stdio.h> and <stdlib.h> by default. This can lead to different results.

Clone this wiki locally