Solution to the failure of loading dynamic library when Linux program is running

Solution to the failure of loading dynamic library when Linux program is running

Unable to load dynamic library under Linux

When the following abnormal situation occurs

./test: error while loading shared libraries: libmfs_open.so: cannot open shared object file: No such file or directory

If the path of the dynamic library is (/usr/cluster/.share/lib)

Solution:

Method 1: Add the path to the /etc/ld.so.conf file, vi /etc/ld.so.conf

Add the following content

include ld.so.conf.d/*.conf

/usr/cluster/.share/lib

Method 2: Enter in the terminal: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/cluster/.share/lib

Method 3: Modify the /etc/profile file

export MPI_HOME=/usr/cluster

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MPI_HOME/.share/lib

Execute source /etc/profile in the terminal to make the configuration file take effect

Solution to the failure of loading dynamic library when the program is running

The error message is as follows:

error while loading shared libraries: libjson.so.0: cannot open shared object file: No such file or directory

There are generally two reasons. One is that the shared library (lib*.so.* file) is not included in the operating system or the shared library version is incorrect. The solution is to download and install it again.

Another reason is that the shared library has been installed, but when the program that needs to call the shared library is executed, the program cannot find the shared library file according to the default shared library path. The solution is as follows:

If the shared library file is installed in the /lib or /usr/lib directory, execute the ldconfig command.

The purpose of the ldconfig command is to search for sharable dynamic link libraries (formatted like lib*.so*) in the default search directories (b and /usrb) and the directories listed in the dynamic library configuration file /etc/ld.so.conf, and then create the connection and cache files required by the dynamic loader (ld.so). The cache file defaults to /etc/ld.so.cache, which stores the sorted list of dynamic link library names.

If the shared library file is installed to /usr/local/lib (generally open source shared libraries are installed to this directory) or other directories other than /lib or /usr/lib, then before executing the ldconfig command, you must also add the new shared library directory to the shared library configuration file /etc/ld.so.conf, as follows:

# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/usr/local/lib" >> /etc/ld.so.conf
#ldconfig

Or create a new file with .conf as the suffix in the /etc/ld.so.conf.d/ directory and add the directory where the library file is located to the file. Then execute ldconfig to update the /etc/ld.so.cache file.

If the shared library file is installed in a directory other than /lib or /usr/lib, but you do not want to add the shared library path to the /etc/ld.so.conf file (or you do not have permission to add the path). You can export a global variable LD_LIBRARY_PATH , and then when you run the program it will look for the shared library in a directory.

LD_LIBRARY_PATH means to tell the loader in which directories to find shared libraries. You can set multiple search directories, separated by colons. For example, if you installed mysql to the /usr/local/mysql directory, and there are a lot of library files under /usr/local/mysql/lib, you can add the following statement to .bashrc or .bash_profile or shell:

export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH

Generally speaking, this is just a temporary solution, used when there is no permission or temporary need.

If the library file required by the program is lower than the version of the library file currently existing in the system, a link can be made. for example:

error while loading shared libraries: libncurses.so.4: cannot open shared
object file: No such file or directory
ls /usr/lib/libncu*
/usr/lib/libncurses.a /usr/lib/libncurses.so.5
/usr/lib/libncurses.so /usr/lib/libncurses.so.5.3

It can be seen that although there is no libncurses.so.4, there is libncurses.so.5, which is backward compatible.

Just create a link

ln -s /usr/lib/libncurses.so.5.3 /usr/lib/libncurses.so.4

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Build a Scala environment under Linux and write a simple Scala program
  • Common Linux English Error Chinese Translation (Newbies Must Know)
  • WePY cloud development practice in Linux command query applet
  • How to enter directory/folder in Linux without using CD command
  • Three ways to check whether a port is open in a remote Linux system
  • Detailed Linux installation tutorial
  • Detailed instructions for installing Swoole from source code package under Linux and basic usage operations
  • Detailed explanation of chmod command usage in Linux
  • Explanation of several ways to run Tomcat under Linux
  • How to install the standalone version of spark in linux environment without using hadoop

<<:  jQuery plugin to achieve code rain effect

>>:  jQuery plugin to implement floating menu

Recommend

A brief analysis of MySQL parallel replication

01 The concept of parallel replication In the mas...

Detailed explanation of using pt-heartbeat to monitor MySQL replication delay

pt-heartbeat When the database is replicated betw...

Introduction to the use of common Dockerfile commands

Table of contents 01 CMD 02 ENTRYPOINT 03 WORKDIR...

HTML+jQuery to implement a simple login page

Table of contents Introduction Public code (backe...

Detailed explanation of mixins in Vue.js

Mixins provide distributed reusable functionality...

MySQL 5.7.19 winx64 free installation version configuration tutorial

mysql-5.7.19-winx64 installation-free version con...

5 solutions to CSS box collapse

First, what is box collapse? Elements that should...

Linux installation apache server configuration process

Prepare the bags Install Check if Apache is alrea...

Summary of common operation skills of MySQL database

This article summarizes common operating techniqu...

Example of converting webpack images to base64

Download url-loader yarn add -D url-loader module...

MySQL insert json problem

MySQL 5.7.8 and later began to support a native J...

Solution to the problem of z-index not taking effect in CSS3

I recently wrote a combination of CSS3 and js, an...

MySQL 5.7 installation and configuration method graphic tutorial

This tutorial shares the installation and configu...