Ask Your Question

matpen's profile - activity

2017-09-18 22:31:22 +0200 commented question sage LD_LIBRARY_PATH

@dan_fuela thank you, just tried, but that leads to the same results (either library not found, or libblas conflict)

2017-09-18 14:14:52 +0200 received badge  Student (source)
2017-09-18 14:08:48 +0200 asked a question sage LD_LIBRARY_PATH

I wrote a C++ library and the related python bindings, and I would like to make use of them from sage. But whatever I try, I cannot get sage to load the library. Here is what I tried:

1) FIRST ATTEMPT

export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/mylib/lib::/opt/mylib/dependencies"

However, when I try to import from a jupyter notebook:

import mylib.mymodule.mysubmodule

I get the error:

ImportError: /usr/lib/libblas.so.3: undefined symbol: sgemv_thread_n

I only could find one reference (ticket 22006 on http://trac.sagemath.org - sorry, cannot post links yet) to a similar problem, however without resolution (the suggested workaround, namely to install libopenblas-dev did not work for me). Note that mylib does not depend in any way on BLAS.

2) SECOND ATTEMPT

export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
echo -e "/opt/mylib/lib\n/opt/mylib/dependencies" > /etc/ld.so.conf/mylib.conf
sudo ldconfig

But the library cannot be found this way:

ImportError: libmylib.so.1: cannot open shared object file: No such file or directory

3) THIRD ATTEMPT

export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/lib/sagemath/local/lib/libmylib.so.1
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/local/lib/libmylib.so.1

This results in the same import error as in SECOND ATTEMPT.

4) FOURTH ATTEMPT

export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /lib/libmylib.so.1

Now the library finally got loaded, but it cannot find its dependencies.

ImportError: libdependency1.so.1.2.3: cannot open shared object file: No such file or directory

THE QUESTION

What is the proper way to make sage resolve a custom library and its dependencies? I understand that sage tries to isolate itself as much as possible from the system, and I have also read that there is some "magic" going on to adjust environment variables: this seems to cause the problem (1).

ADDITIONAL INFO

Working on Ubuntu 16.04 LTS with sage installed from ppa as follows:

apt-add-repository -y ppa:aims/sagemath
apt-get update
apt install sagemath-upstream-binary

Note that everything works as expected when using the library from the system python console.