Skip to content

Instantly share code, notes, and snippets.

@asterite
Created December 4, 2015 13:34
Show Gist options
  • Save asterite/28ec169fb686f2e53e7d to your computer and use it in GitHub Desktop.
Save asterite/28ec169fb686f2e53e7d to your computer and use it in GitHub Desktop.
libmylib.so: mylib.cr
crystal mylib.cr --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" -o libmylib.dylib
.PHONY: clean run
clean:
rm *.dylib
run: libmylib.dylib
ruby mylib.rb
fun add(a : Int32, b : Int32) : Int32
a + b
end
require 'fiddle'
require 'fiddle/import'
module MyLib
extend Fiddle::Importer
dlload 'libmylib.dylib'
extern 'int add(int, int)'
end
puts MyLib.add(11, 31)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment