Skip to content

Instantly share code, notes, and snippets.

@mwlang
Created May 8, 2019 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwlang/6db6a1609f83ed112639a1cf527ae8f8 to your computer and use it in GitHub Desktop.
Save mwlang/6db6a1609f83ed112639a1cf527ae8f8 to your computer and use it in GitHub Desktop.
cc -bundle -L/usr/local/opt/crystal/embedded/lib -o cr_math.bundle cr_math.o
Undefined symbols for architecture x86_64:
"_GC_free", referenced from:
_*GC::free<Pointer(Void)>:Nil in cr_math.o
"_GC_get_push_other_roots", referenced from:
_*GC::before_collect<&Proc(Nil)>:Nil in cr_math.o
"_GC_init", referenced from:
_*GC::init:Nil in cr_math.o
"_GC_malloc", referenced from:
_*GC::malloc<UInt64>:Pointer(Void) in cr_math.o
"_GC_malloc_atomic", referenced from:
_*GC::malloc_atomic<UInt64>:Pointer(Void) in cr_math.o
"_GC_pthread_detach", referenced from:
_*GC::pthread_detach<Pointer(Void)>:Int32 in cr_math.o
"_GC_push_all_eager", referenced from:
_*GC::push_stack<Pointer(Void), Pointer(Void)>:Nil in cr_math.o
"_GC_realloc", referenced from:
_*GC::realloc<Pointer(Void), UInt64>:Pointer(Void) in cr_math.o
"_GC_register_finalizer_ignore_self", referenced from:
_*GC::add_finalizer_impl<IO::Encoder>:Nil in cr_math.o
_*GC::add_finalizer_impl<Thread::Mutex>:Nil in cr_math.o
_*GC::add_finalizer_impl<Thread>:Nil in cr_math.o
_*GC::add_finalizer_impl<File>:Nil in cr_math.o
_*GC::add_finalizer_impl<IO::FileDescriptor>:Nil in cr_math.o
_*GC::add_finalizer_impl<IO::Decoder>:Nil in cr_math.o
"_GC_set_handle_fork", referenced from:
_*GC::init:Nil in cr_math.o
"_GC_set_push_other_roots", referenced from:
_*GC::before_collect<&Proc(Nil)>:Nil in cr_math.o
"_GC_stackbottom", referenced from:
_*GC::stack_bottom:Pointer(Void) in cr_math.o
_*GC::stack_bottom=<Pointer(Void)>:Pointer(Void) in cr_math.o
"_event_add", referenced from:
_*Crystal::Event#add<Nil>:Int32 in cr_math.o
_*Crystal::Event#add<struct.LibC::Timeval>:Int32 in cr_math.o
"_event_base_loop", referenced from:
_*Crystal::Event::Base#run_loop:Int32 in cr_math.o
"_event_base_new", referenced from:
_*Crystal::Event::Base#initialize:Pointer(Void) in cr_math.o
"_event_free", referenced from:
_*Crystal::Event#free:Bool in cr_math.o
"_event_new", referenced from:
_*Crystal::Event::Base#new_event<Int32, LibEvent2::EventFlags, File, &Proc(Int32, LibEvent2::EventFlags, Pointer(Void), Nil)>:Crystal::Event in cr_math.o
_*Crystal::Event::Base#new_event<Int32, LibEvent2::EventFlags, IO::FileDescriptor+, &Proc(Int32, LibEvent2::EventFlags, Pointer(Void), Nil)>:Crystal::Event in cr_math.o
_*Crystal::Event::Base#new_event<Int32, LibEvent2::EventFlags, IO::FileDescriptor, &Proc(Int32, LibEvent2::EventFlags, Pointer(Void), Nil)>:Crystal::Event in cr_math.o
_*Crystal::Event::Base#new_event<Int32, LibEvent2::EventFlags, Fiber, &Proc(Int32, LibEvent2::EventFlags, Pointer(Void), Nil)>:Crystal::Event in cr_math.o
"_iconv", referenced from:
_*Iconv#convert<Pointer(Pointer(UInt8)), Pointer(UInt64), Pointer(Pointer(UInt8)), Pointer(UInt64)>:UInt64 in cr_math.o
"_iconv_close", referenced from:
_*Iconv#close:Nil in cr_math.o
"_iconv_open", referenced from:
_*Iconv#initialize<String, String, (Symbol | Nil)>:Nil in cr_math.o
"_pcre_free", referenced from:
___crystal_main in cr_math.o
"_pcre_malloc", referenced from:
___crystal_main in cr_math.o
"_rb_cObject", referenced from:
_Init_cr_math in cr_math.o
"_rb_define_class", referenced from:
_Init_cr_math in cr_math.o
"_rb_define_method", referenced from:
_Init_cr_math in cr_math.o
"_rb_int2inum", referenced from:
_*fibonacci_cr_wrapper<Pointer(Void), Pointer(Void)>:Pointer(Void) in cr_math.o
"_rb_num2int", referenced from:
_*fibonacci_cr_wrapper<Pointer(Void), Pointer(Void)>:Pointer(Void) in cr_math.o
"_setup_sigfault_handler", referenced from:
___crystal_main in cr_math.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [cr_math.bundle] Error 1
lib CrRuby
type VALUE = Void*
type METHOD_FUNC = VALUE, VALUE -> VALUE
$rb_cObject : VALUE
fun rb_num2int(value : VALUE) : Int32
fun rb_int2inum(value : Int32) : VALUE
fun rb_define_class(name: UInt8*, super: VALUE) : VALUE
fun rb_define_method(klass: VALUE, name: UInt8*, func: METHOD_FUNC, argc: Int32)
end
def fibonacci_cr_wrapper(self : CrRuby::VALUE, value : CrRuby::VALUE)
int_value = CrRuby.rb_num2int(value)
CrRuby.rb_int2inum(fibonacci_cr(int_value))
end
def fibonacci_cr(n)
n <= 1 ? n : fibonacci_cr(n - 1) + fibonacci_cr(n - 2)
end
fun init = Init_cr_math
GC.init
LibCrystalMain.__crystal_main(0, Pointer(Pointer(UInt8)).null)
cr_math = CrRuby.rb_define_class("CrMath", CrRuby.rb_cObject)
CrRuby.rb_define_method(cr_math, "fibonacci", ->fibonacci_cr_wrapper, 1)
end
CRYSTAL = crystal
UNAME = "$(shell uname -ms)"
LIBRARY_PATH = $(shell brew --prefix crystal-lang)/embedded/lib
TARGET = cr_math.bundle
$(TARGET): cr_math.o
$(CC) -bundle -L$(LIBRARY_PATH) -o $@ $^
cr_math.o: cr_math.cr
$(CRYSTAL) build -v --cross-compile $(UNAME) $<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment