sergot / openssl

OpenSSL bindings for Perl 6
MIT License
14 stars 31 forks source link

Add info to readme that libssl.so is required to exist in the library search path. #16

Open Rotwang opened 8 years ago

Rotwang commented 8 years ago

On ubuntu 15.10 by default openssl package pulls in libssl1.0.0 package which contains versioned libssl:

# dpkg -L libssl1.0.0 | grep libssl[.]so
/lib/x86_64-linux-gnu/libssl.so.1.0.0

Unfortuantely such library isn't fount by default by the dlopen (dlopen is used by dyncall library used by moar and nqp):

# cat t.c
#include <dlfcn.h>
#include <stdio.h>

int main (void) {
    printf("%p\n", dlopen("libssl.so", RTLD_LAZY));
    return 0;
}
# gcc -o t t.c  -ldl
# ./t
(nil)

Perl6 example:

$ perl6 --version
This is Rakudo version 2015.12-36-g64a61a3 built on MoarVM version 2015.12
implementing Perl 6.c.
$ cat t
#!/usr/bin/env perl6

use v6;
use NativeCall;

sub SSL_library_init() is native('ssl') { ... }
SSL_library_init();
$ perl6 t
NativeCall: Consider adding the api version of the library you want to use, sub foo is native(ssl, v1)
Cannot locate native library 'libssl.so': libssl.so: cannot open shared object file: No such file or directory
  in method setup at /home/ubuntu/.rakudobrew/moar-nom/install/share/perl6/sources/DA0980735978E745E73F676402B9B166FEBF3818 line 230
  in method CALL-ME at /home/ubuntu/.rakudobrew/moar-nom/install/share/perl6/sources/DA0980735978E745E73F676402B9B166FEBF3818 line 241
  in block <unit> at t line 7

When we pass version along with the library dlopen and NativeCall work properly:

# cat t.c
#include <dlfcn.h>
#include <stdio.h>

int main (void) {
    printf("%p\n", dlopen("libssl.so.1.0.0", RTLD_LAZY));
    return 0;
}
# gcc -o t t.c  -ldl
# ./t
0xe40040

Perl6 example:

$ cat t
#!/usr/bin/env perl6

use v6;
use NativeCall;

sub SSL_library_init() is native('ssl', v1.0.0) { ... }
SSL_library_init();
$ perl6 t
$ echo $?
0

However unversioned libssl resides in libssl-dev:

# dpkg -L libssl-dev | grep libssl[.]so
/usr/lib/x86_64-linux-gnu/libssl.so

I see two distinct reasonable ways to remedy headaches in the future: