Fury
Fury

Reputation: 85

Is it possible to permanently add directories to the default ld search path?

I'm attempting to install a library that will be used generally on this node. Currently the library is installed in a location that includes it's version name /opt/sample-x.y.z/lib/libsample.so. Ideally I'd like to be able to update the library, change the sys configs and not bother other devs with needing to change paths on trivial changes. I've added the library directory to the /etc/ld.so.conf.d/sample.conf and run ldconfig, but this only seems to affect loading not linking.

When I run ldconfig -v | grep sample, I correctly see libsample.so.

However, whenever I run ld -lsample --verbose, it fails to find the library. In the verbose output, it details the directories that it searches and the one I added with ldconfig isn't there. As a workaround, I tested adding a symlink to the library in /usr/lib and ld was able to find it.

Are there other ways to add the library to the default linker path? Ideally I'm looking for a config file that I can modify similar to the one for loading.

If it matters, the node is a Centos7 node.

Upvotes: 2

Views: 1324

Answers (1)

Fury
Fury

Reputation: 85

No, it is not possible. The paths that ld uses during the linking phase are configured via scripts which are pulled into ld during its build process. There isn't a way to update these after ld is built. There are other questions and answers related to accomplishing this for GCC specifically which seem to involve the LIBRARY_PATH environment variable. That solution, however, is gcc specific.

Upvotes: 2

Related Questions