Reputation: 33
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); }
Upvotes: 2
Views: 3462
Reputation: 901
${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.
Upvotes: 3
Reputation: 1319
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
Upvotes: 2
Reputation: 15121
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.
Upvotes: 1