SciRuby / rubex

rubex - A Ruby-like language for writing Ruby C extensions.
BSD 2-Clause "Simplified" License
451 stars 21 forks source link

Linking external C library #62

Open arjunmenon opened 6 years ago

arjunmenon commented 6 years ago

Hey I am trying to understand correct way to create bindings to any external C libs.

C lib - https://github.com/wooorm/levenshtein.c

rubex file

lib "<levenshtein.h>"
    unsigned int levenshtein(char *a, char *b)
end

class Lev
    def self.distance(a, b)
        return levenshtein(a, b)
    end
end

Error

>:~/Desktop/c/levenshtein.c$ rubex lev.rubex 
creating Makefile

>:~/Desktop/c/levenshtein.c$ cd lev/

>:~/Desktop/c/levenshtein.c/lev$ ruby extconf.rb // added all lib files
creating Makefile

>:~/Desktop/c/levenshtein.c/lev$ make
compiling lev.c
compiling __rubex__common_utils_.c
linking shared-object /home/arjun/Desktop/c/levenshtein.c/lev/lev.so

>:~/Desktop/c/levenshtein.c/lev$ ruby rb_lev.rb 
#<Lev:0x0055a47eb7f868>
ruby: symbol lookup error: /home/arjun/Desktop/c/levenshtein.c/lev/lev.so: undefined symbol: levenshtein

>:~/Desktop/c/levenshtein.c/lev$ ls
extconf.rb  levenshtein.c  lev.h  lev.so    rb_lev.rb                 __rubex__common_utils_.h
lev.c       levenshtein.h  lev.o  Makefile  __rubex__common_utils_.c  __rubex__common_utils_.o

Why am I getting this error?

Rubex - 0.1.2 Ruby 2.3.3

arjunmenon commented 6 years ago

Hi Any updates on this? Is there any condition on the type of C libs we can link with Rubex?