How to add a dynamic link library in CentOS

Source: Internet
Author: User

How to add a dynamic link library in CentOS

After compiling some C/C ++ files, when running, an error is reported that the shared library cannot be loaded. For example:

[Plain] view plaincopy
  1. ./Write: errorwhileloadingsharedlibraries: libhdfs. so.0.0.0: cannotopen#dobjectfile: Nosuchfileordirectory

This error occurs because a shared library is required during the compilation process. For example, the write executable program depends on a shared library called libhdfs. so. (For details about the differences between dynamic and static link libraries, refer to the Baidu documentation)

There are two ways to solve the problem above. either of the following two methods can be used:

First, add the path of the shared library to/etc/profile:

[Plain] view plaincopy
  1. ExportLD_LIBRARY_PATH = $ JAVA_HOME/jre/lib/amd64/server:/home/dcc/libhdfs

As shown in the preceding figure, two shared libraries are added. Note that the libraries are separated by colons.

Second, add the path to/etc/ld. so. conf and reload the Shared Library:

[Plain] view plaincopy
  1. Vi/etc/ld. so. conf
After editing: [plain] view plaincopy
  1. Includeld. so. conf. d/*. conf
  2. /Home/dcc/libhdfs
  3. /Usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/ server/
Two paths are added, each of which occupies one row. After editing, reload the database:

[Plain] view plaincopy
  1. /Sbin/ldconfig-v

As for the differences between the two methods, I guess that the first method is to load only when the C/C ++ program is executed, and the second method should be for the entire system, load at startup.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.