Use of -L/tmp -l on linux

Roy Colica

Use of -L/tmp -l on linux

Hi all,
I'm porting some sw from HP-UX on Linux.
I understand is not possible to use when linking a shared library (.so) the following -L/tmp
Do you know how can I proceed? Do I have to rename in and use the following "-L/tmp -ltest"?
I'd prefer not to change all my libs names...
Can you please help?
Mike Stroyan
Honored Contributor

Re: Use of -L/tmp -l on linux

Changing your library names to the lib*.so convention will be the least troublesome in the long run.

The linux ld does not have any way to combine the -L search path with arbitrarily named library files. You could link with /tmp/ But if you try to link with absolute or relative paths to such files then ld will record the path by default. The runtime loader will then inflexibly look for the libraries at exactly the same paths without regard for LD_LIBRARY_PATH. It is possible to use "ld -soname" when creating your shared library to make ld remember the plain file name instead of the path. Then you could link with /tmp/ and later install your shared library in a different directory.

If you choose to rename your libraries to match the lib*.so convention you could also consider using the versioning naming convention. That will allow you to create future versions that are incompatible with the current libraries but can be installed simultaneously on the same system. To use a version number you need to set the library name with "ld -soname" to include a version number and also provide a plain lib*.so symbolic link for ld to find when linking.

There is a good discussion of linux shared library conventions at
which discusses how to create and install shared libraries.