Error finding shared libraries when running executable

I’m trying to call a executable from Julia using the run() command but am having some issues.I have a command that calls a Fortran executable with a number of arguments exe --flag arg --flag2 arg and I can successfully run this command from both the command line and the terminal inside of VSCode however when I call run(bash -c exe --flag arg --flag2 arg)

I get an error that one of the .so libraries is not found: error while loading shared libraries: example.so: cannot open shared object file: No such file or directory I have tried adding the library to the $PATH variable inside of julia but when I call run(echo $PATH) I get that the variable is not defined.

What am I missing in my understanding of how the run() command works? If anyone could help I’d appreciate it

First, run(`echo $PATH`) will not work: that is interpolating a Julia variable named PATH into the arguments used for launching echo, which fails since you haven’t (and shouldn’t) define a Julia variable named PATH.

(Realize that run is not launching a shell (like bash) and then passing it a string, it’s instead spawning programs directly. If you want a shell command, you have to launch the shell yourself, e.g. via run(`bash -c "echo \$PATH"`).)

What you want to make sure the path environment variables are set correctly. For example, you can check the PATH environment variable in Julia with ENV["PATH"] (without using run). However, if you are opening .so files I’m guessing you are on a Unix variant, in which case the relevant environment variable is LD_LIBRARY_PATH (which tells the runtime linker where to find shared libraries), not PATH (which tells the shell where to find executables).

1 Like

Adding the folder of .so files to the LD_LIBRARY_PATH worked. Thank you so much for helping clear this up.

1 Like