Skip to content

Linking external C library #62

@arjunmenon

Description

@arjunmenon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions