Tuesday, May 5, 2020

Solaris: Shared Library Error: "ld.so.1: cannot open shared_library_name"

Symptoms
Setting LD_LIBRARY_PATH or compiling/linking with -L can cause programs to be unable to find shared libraries.

For example, LD_LIBRARY_PATH was set to /usr/openwin/lib when this error
appeared:

"ld.so.1: myprogram : fatal : libXt.so.4 : cannot open file : error no 2"
Cause
Different LD_LIBRARY_PATH settings can have a variety of effects when linking, compiling and finding shared libraries for a given application.
Solution
The following tips are recommended for overcoming the above problem:

1. When linking (using a compiler, ld, or ild), use the -R option to specify the path used by ld.so.1 (the runtime linker) to search for shared libraries at runtime. This is preferable to using LD_RUN_PATH or LD_LIBRARY_PATH.

Note: The linker behavior changed from SunOS 4.x to Solaris. In SunOS 4.x, -L specified the search paths at both link (build) time and run time. However, in Solaris (SunOS 5.x), -L specifies link time paths and -R specifies run time paths.

The behavior of LD_LIBRARY_PATH in releases of SunOS 4.x is also different than the behavior in the current version of Solaris. Refer to the ld and ld.so.1 man pages for implementation details.

2. Check permissions and the ownership of libraries and the directories that contain them.

Use ldd to list the executable's dynamic dependencies (required libraries). The ldd command lists the path to all libraries that can be found and indicates the required libraries that cannot be found.

Note: Library resolution is dependent upon the environment. If you use ldd in an environment other than where the problem is occurring, the ldd command may locate libraries that can not be located under actual use, or could even resolve dependencies with different libraries.

3. If the executable has setuid permission, only trusted directories in the LD_LIBRARY_PATH setting are searched; other paths are ignored. Use crle(1) to set the secure path and/or copy your shared libraries to the designated secure path if setuid permission is needed.


4. Use the following command to find the path used by to locate
shared libraries at run time:
dump -Lv | grep RPATH
5. If in doubt, and setuid permission have not been given to the executable, use truss(1) to determine the setting for LD_LIBRARY_PATH and to check the search order used by the runtime linker to find shared libraries.


No comments:

Post a Comment