Clone or download
larskanis Merge pull request #662 from IgorJorobus/master
Added specs for FFI::LastError.winapi_error()
Latest commit 1ddc987 Jan 10, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
bench fix tests for netbsd Jul 1, 2014
ext/ffi_c Merge pull request #633 from graywolf/add_win_error Jan 6, 2019
gen Keep a log of generated types.conf files Nov 13, 2011
lib Bump VERSION to 1.10.0 Jan 6, 2019
libtest Synchronize changes between libtest and spec/ffi/fixtures directories. Aug 6, 2015
nbproject Add custom data converters for parameter and return types May 22, 2010
samples Fix qsort example for 64bit Dec 12, 2009
spec Added specs for FFI::LastError.winapi_error() Jan 9, 2019
.gitignore Fix compatibility with PPC64LE platform (#577) Jul 12, 2017
.gitmodules Fix compatibility with PPC64LE platform (#577) Jul 12, 2017
.travis.yml Remove rubinius, since it seems to be no longer available on Travis-CI Jan 6, 2019
.yardopts Don’t explicitly state markdown markup in YARD options Aug 6, 2011 Bump VERSION to 1.10.0 Jan 6, 2019
COPYING Switch license to BSD throughout codebase. See #288. Oct 29, 2013
Gemfile Update rake-compiler-dock to add binary gem support for ruby-2.6 Jan 6, 2019
LICENSE update license Jul 11, 2016
LICENSE.SPECS Change licensing of the specs to the same license as Rubyspec Nov 25, 2012 Revert "README: Remove now unnecessary PaX workaround [ci skip]" Jun 3, 2018
Rakefile Enable gem:windows on JRuby and avoid extra downloads while cross build Jan 6, 2019
appveyor.yml Appveyor: Replace deprecated gem install options Jan 6, 2019
ffi.gemspec Various fixes and more deterinistic gem packaging (#612) Feb 12, 2018

ruby-ffi Build Status Build status Windows


Ruby-FFI is a ruby extension for programmatically loading dynamic libraries, binding functions within them, and calling those functions from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby and JRuby. Discover why you should write your next extension using Ruby-FFI.


  • Intuitive DSL
  • Supports all C native types
  • C structs (also nested), enums and global variables
  • Callbacks from C to ruby
  • Automatic garbage collection of native memory


require 'ffi'

module MyLib
  extend FFI::Library
  ffi_lib 'c'
  attach_function :puts, [ :string ], :int

MyLib.puts 'Hello, World using libc!'

For less minimalistic and more sane examples you may look at:


You need a sane building environment in order to compile the extension. At a minimum, you will need:

  • A C compiler (e.g. Xcode on OSX, gcc on everything else)
  • libffi development library - this is commonly in the libffi-dev or libffi-devel

On Linux systems running with PaX (Gentoo, Alpine, etc.) FFI may trigger mprotect errors. You may need to disable mprotect for ruby (paxctl -m [/path/to/ruby]) for the time being until a solution is found.


From rubygems:

[sudo] gem install ffi

or from the git repository on github:

git clone git://
git submodule update --init --recursive
cd ffi
rake install


The ffi library is covered by the BSD license, also see the LICENSE file. The specs are shared with Rubyspec and are licensed by the same license as Rubyspec, see the LICENSE.SPECS file.


The following people have submitted code, bug reports, or otherwise contributed to the success of this project: