2

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); }
0

3 Answers 3

3

${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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.