Question

I'm trying to use the command:

gcc -I${HOME}/usr/include -L${HOME}/usr/lib -lsodium test.c

but when I try and run a.out it gives the error:

./a.out: error while loading shared libraries: libsodium.so.4: cannot open shared object file: No such file or directory

but libsodium.so.4 is definitely in the ${HOME}/usr/lib directory. What's going on? test.c is just

#include <stdio.h>
#include "sodium.h"
int main(int argc, char** argv)
{ return (0); }
Was it helpful?

Solution 3

Please

export LD_LIBRARY_PATH=${HOME}/usr/lib

first and try again.

That export ... will tell loader (ld-linux.so) also search ${HOME}/usr/lib for shared libraries.

OTHER TIPS

${HOME}/usr/lib is not in your runtime library path.

You can bake the path into your executable using the gcc option -Wl,-rpath,${HOME}/usr/lib or set the environment variable LD_LIBRARY_PATH=${HOME}/usr/lib before executing the program.

ldd a.out will tell you if libsodium can be found in your runtime library path, and if so, the location of the library.

You need to tell the runtime linker where to find the .so. Typically this is done with the LD_LIBRARY_PATH environment variable, so you would invoke a.out like so (assuming you're using a bash-like shell):

LD_LIBRARY_PATH=${HOME}/usr/lib ./a.out

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top