If you want to avoid LD_LIBRARY_PATH, you can also do this, during linking:
gcc -o exename -L/path/to/dynamiclib/ -lnameofLib \
-Wl,-R/path/to/dynamiclib/ sourceCode1.c ...
The -Wl,... is used to pass extra commands to the linker, and in this case, with -R you tell the linker to store this path as the "default search path" for the .so.
I keep notes of many small tips like this one, at my site:
http://users.softlab.ntua.gr/~ttsiod/tricks.htmlhttps://www.thanassis.space/tricks.html