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
- ./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
- 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
- Vi/etc/ld. so. conf
After editing: [plain] view plaincopy
- Includeld. so. conf. d/*. conf
- /Home/dcc/libhdfs
- /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
- /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.