How to link to a shared library without lib* prefix in a different directory?

gcc, linker, shared-libraries

Solution

-Wl,-rpath,. --> to use current directory for searching lib files. (even if not found in compilation, ok at run-time) instead of -llibrary --> use library.so.

This seems to work correctly. Hope anyone finds this useful.

Problem

I have to link my code to a shared library without the lib prefix. (say, foo.so) The first problem is -l option does not find the file. So I tried directly including this file to the last compilation like this: gcc a a.o /PATH/TO/FOO/foo.so But in this case, a is hard linked to foo.so as an absolute path as seen in "ldd a": /PATH/TO/FOO/foo.so In the final deployment both files would end up being in the same folder, so this should be normal link, not the absolute path. How can I do this?

Original source

Related problems