6

Problem

I am trying to call cumulative distribution function of chisq function in GSL from raku.

This is my raku script chisq.raku

#Calling gsl_cdf_chisq-P function in GSL from raku

use NativeCall;

sub gsl_cdf_chisq_P(num64, num64) returns num64 is native('gsl') { * };
sub gsl_cdf_chisq_Q(num64, num64) returns num64 is native('gsl') { * };


sub pchisq($q, $df, $lower-tail = True) {
  my $a = $q.Num;
  my $b = $df.Num;
  if $lower-tail == True {
    return gsl_cdf_chisq_P($a, $b)
  } else {
    return gsl_cdf_chisq_Q($a, $b)
  }
  }

say pchisq(3,4);

While executing this script, I get following error:

Cannot locate native library '(null)': /usr/lib/x86_64-linux-gnu/libgsl.so: undefined symbol: cblas_ctrmv
  in method setup at /usr/share/perl6/core/sources/947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B (NativeCall) line 286
  in block gsl_cdf_chisq_P at /usr/share/perl6/core/sources/947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B (NativeCall) line 578
  in sub pchisq at chisq.raku line 13
  in block <unit> at chisq.raku line 19

From reading the documentation on NativeCall, I am including the shared library libgsl.so.

Googling showed cblas_ctrmv was possibly (not sure) related with lapack.

So I searched for liblapack.so which was indeed present inside /usr/lib. echo $LD_LIBRARY_PATH showed

/usr/local/lib/R/lib::/lib:/usr/local/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server

To see if I can fix it, I added /usr/lib to LD_LIBRARY_PATH with command export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib and tried to run the script again.

Still not working, same error message.

Environment:

I am running code in docker container inside rstudio.

Raku version 2019.11

It has gsl-dev files and gsl library. The container has shared library libgsl.so inside /usr/lib/x86_64-linux-gnu/. Other shared libraries inside this folder are enter image description here

Is there a way to make it work?

Community
  • 1
  • 1
Suman Khanal
  • 3,079
  • 1
  • 17
  • 29
  • 1
    If I understand this correctly, this is a shared library that is called from another shared library, is that correct? My hunch here is that the second, shared, library is not loaded. What I would do is to declare the `cblas_ctrmv` with its corresponding library within the script, so that its library is registered and thus it can be called. – jjmerelo Dec 11 '19 at 17:31
  • 1
    Also note that Fernando Santagata is working on a GSL module, I believe. – Elizabeth Mattijsen Dec 11 '19 at 17:54
  • 2
    I tested the code on Ubuntu 19.10, and it worked (I already had installed gsl library) immediately. The output was: 0.4421745996289249. – Håkon Hægland Dec 11 '19 at 18:25
  • 2
    Possibly related: https://stackoverflow.com/questions/49036300/nativecall-loading-a-library-symbol-i-dont-call Also see rakudo enhancement request: https://github.com/rakudo/rakudo/issues/1584 – Curt Tilmes Dec 11 '19 at 21:09
  • 2
    Yes, I'm working on a libgsl interface module. 561 functions converted so far. – Fernando Santagata Dec 16 '19 at 17:49

2 Answers2

3

I verified that the version of libgsl and libgslcblas shipped with Ubuntu 18.04 produce the kind of error you found. I installed the Debian Buster version of both libraries (even if it's not good practice) and that miraculously cured the problem.

Fernando Santagata
  • 1,487
  • 1
  • 8
  • 15
2

Looks like the base image of rocker/rstudio is updated to debian:buster.

After installation of libgsl23, the problem is resolved.

It works now !!

Suman Khanal
  • 3,079
  • 1
  • 17
  • 29