I am trying to create a simple shared library libfoo.so
which opens a connection to Aerospike server using a single function, waits for 3 seconds and closes the connection. libfoo.so
has a single function open_then_close(char* host, int port)
.
Then I want to invoke this function from Ruby using FFI:
require 'ffi'
module Aerospike
extend FFI::Library
ffi_lib "./libfoo.so", "libaerospike.so"
attach_function :connect_then_close, [:string, :int], :int
end
puts Aerospike.connect_then_close("127.0.0.1", 3000)
I tested foolib.so
using a C program, it works fine. However when I try to run the above code I get the following error:
Could not open library '/usr/lib/libaerospike.so': /usr/lib/libaerospike.so: undefined symbol: GENERAL_NAME_free (LoadError)
Additional info:
$ ldd /usr/lib/libaerospike.so
linux-vdso.so.1 => (0x00007ffe413cb000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2ec87a3000)
/lib64/ld-linux-x86-64.so.2 (0x00005645069a7000)
$ nm -u /usr/lib/libaerospike.so | grep GENERAL_NAME_free
U GENERAL_NAME_free
Any idea what is wrong?
UPDATE
$ dpkg -l | grep libgcrypt
ii libgcrypt11:amd64 1.5.3-2ubuntu4.3 amd64 LGPL Crypto library - runtime library
$ locate libcrypto
/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
/usr/lib/x86_64-linux-gnu/libcrypto.a
/usr/lib/x86_64-linux-gnu/libcrypto.so
/usr/lib/x86_64-linux-gnu/pkgconfig/libcrypto.pc
This is how I compiled and created libfoo.so
$ gcc -Wall -c -fPIC foo.c -o foo.o -laerospike -lssl -lcrypto -lpthread -lm -lz
Linking the wrong way:
$ gcc -shared -o libfoo.so foo.o