Ask Your Question
1

sage LD_LIBRARY_PATH

asked 2017-09-18 03:15:57 -0600

matpen gravatar image

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.

edit retag flag offensive close merge delete

Comments

What about the following scenario? (Written only with the hope of isolating the problem point.)

  • starting a terminal, typing in it

    sage -sh

    to start the sage shell, which sets all environment variables as needed, then

  • extending / setting the needed variables SAGE_PATH, and LD_LIBRARY_PATH as in one of the attempts,

  • starting sage in this terminal and testing

  • and / or starting jupyter from this terminal and testing.

dan_fulea gravatar imagedan_fulea ( 2017-09-18 14:25:11 -0600 )edit

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

matpen gravatar imagematpen ( 2017-09-18 15:31:22 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-09-29 05:45:44 -0600

Jeroen Demeyer gravatar image

I think the easiest solution is to install your library and bindings inside the Sage environment instead of in /opt/mylib. Run

sage --sh

which will drop you in a "Sage shell". Now, install your stuff in $SAGE_LOCAL. For an autotools project, this would be

./configure --prefix="$SAGE_LOCAL" && make && make install

For a Python project, plain pip will work:

pip install PKGNAME
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-09-18 03:15:57 -0600

Seen: 89 times

Last updated: Sep 29