0
votes

I'm trying to compile and run some c++ code on google colab, which depends on the GSL library. An import step is to make sure several key files (libgsl.so.25, for example) are located in the folder associated with your LD_LIBRARY_PATH environment variable. Currently, LD_LIBRARY_PATH is set as;

!echo $LD_LIBRARY_PATH
.
.
/usr/lib64-nvidia

So now, I want to change LD_LIBRARY_PATH to the folder containing libgsl.so.25, which is /content/lib. From the gnu documentation (https://www.gnu.org/software/gsl/doc/html/usage.html#f4) you can change LD_LIBRARY_PATH as follows;

!LD_LIBRARY_PATH=/content/lib
!export LD_LIBRARY_PATH

However, it seems as though this didn't actually change LD_LIBRARY_PATH (ie; the same, original path is returned when I !echo). In addition, when I try to run my code, I get the same error message that libgsl.so.25 can not be found.

!echo $LD_LIBRARY_PATH
.
.
/usr/lib64-nvidia

Can anyone see what I'm missing? How can you actually change LD_LIBRARY_PATH?

1
The commands you pasted assume you're working in a single shell. I don't think Colab runs every cell in the same shell. - Botje
@Botje I dont really follow - your saying that if I run !LD_LIBRARY_PATH="/content/bin" !export LD_LIBRARY_PATH !echo $LD_LIBRARY_PATH all together in the same block that should fix the issue? - matthew_obrien
No, I'm saying it will not work because every !... line is executed in a separate shell. - Botje
Hmm..Ok, so do I have any options? - matthew_obrien
If you're compiling the C++ code yourself, can't you set its dynamic RPATH to a static directory like /content/lib or relative to its location using $ORIGIN/../lib or so? - Botje

1 Answers

1
votes

For anyone looking for this solution, use the os.environ

import os os.environ['LD_LIBRARY_PATH']='/path/to/libgsl.so.25'