Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling GSL functions via NativeCall in Raku throws error

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?

like image 875
Suman Khanal Avatar asked Dec 11 '19 17:12

Suman Khanal


2 Answers

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.

like image 186
Fernando Santagata Avatar answered Sep 19 '22 23:09

Fernando Santagata


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

After installation of libgsl23, the problem is resolved.

It works now !!

like image 42
Suman Khanal Avatar answered Sep 20 '22 23:09

Suman Khanal