Speaking of this Lib file, start with a glitch.
A day development said, a test with a virtual machine can ping ssh can't connect. Yun-dimensional classmates hurriedly to check, sshd_config configuration files are correct ah, a little wrong is not, then why?
Test, regardless of their own or other machines, is an error
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/91/61/wKiom1j1tNiwG6XzAABTYHuYQMc027.jpg "title=" SSH connection not on. jpg "alt=" wkiom1j1tniwg6xzaabtyhuyqmc027.jpg "/>
Note here that you are prompted to have a Libcom_err.so.2 shared library file that cannot be found.
Ask for development before they know they're testing a software that accidentally deletes a library file.
Then in the normal machine under the same machine view, and the error of the virtual machine comparison, found that 2 less library files
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/91/60/wKioL1j1tdfzehqVAAB-bnDvJSA177.jpg-wh_500x0-wm_ 3-wmp_4-s_3243228716.jpg "title=" 55.jpg "alt=" Wkiol1j1tdfzehqvaab-bndvjsa177.jpg-wh_50 "/>
Mount the system CD or copy the two files from the normal virtual machine and put them under the lib64.
Try normal again.
650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/91/60/wKioL1j1thLBu3avAABQJqKDyuc847.jpg-wh_500x0-wm_ 3-wmp_4-s_3805855434.jpg "title=" 4545.jpg "alt=" Wkiol1j1thlbu3avaabqjqkdyuc847.jpg-wh_50 "/>
This glitch is easy to solve, so how do you understand the library files in Linux? The study also does not mistake the work.
The library files under Linux are divided into two categories, the shared library and the static library, and the difference between them is only when the code required to execute the program is dynamically loaded at run time, or statically at compile time.
Linux libraries are typically in the/lib or/usr/lib directory, and if the 64-bit system has a lib64 directory. LIB is the English abbreviation of the library, which mainly holds the system's link library files, and the system will not function properly without the directory. The/lib directory stores the shared libraries that the program uses when it runs. By sharing libraries, many programs can reuse the same code, and these libraries can be stored in a common location, thus reducing the size of the running program. This directory contains the various libraries that the program uses when linking.
Knowledge of the Library
1. Naming the Library
The name of the library is relatively simple, the first feature is that all libraries start with LIB, and the GCC command automatically joins Lib before the file name specified by the-l option.
Second feature a library with a file name ending in. A is a static library.
The third feature file name is. So's library is a shared library (the shared library is dynamically loaded at run time). By default, GCC takes precedence over shared libraries when linking, and only considers static libraries if the shared library does not exist.
2, the library number
The library's numbering format is as follows:
library_name . Major.num . minor_.min . Pathch_num
For example, the author of Red Hat Linux 9.0 's gun database is libgdbm.so.0.0.2, which is described in detail as follows:
Library_name is libc.so (standard C library);
Major_num is 2 (major version number);
Minor_.min is 0 (minor version number);
Pathch_num is 0 (patch level number, also known as release number).
3, the operation of the Library command
Linux Library operations can be done using commands, and the commands currently used are LDD and ldconfig.
LDDis the library Dependency display abbreviation, its role isdisplays a shared library that an executable program must use.
(1) command format
ldd [Options] File name
(2) main parameters
-D performs a relocation and reports the missing function.
- R performs relocation of functions and data objects and reports missing functions and data objects.
(3) Application examples
For example, if you are querying the Perl language for shared libraries, you can first use the Find command to query the absolute path of the program, and then use the LDD command:
#find-name Perl
Ldd/usr/bin/perl
$ ldd test
Execute test and you can see how it calls functions in the dynamic library.
2.Ldconfig
The purpose of the Ldconfig command is to determine the running links required for shared libraries that are located under Directories/usr/lib and/lib. The Libs of these links are saved in the/et/ld.so.conf file. Search for a shareable dynamic-link library (in the format described previously, lib*.so*) to create the link and cache files required for the dynamic loader (ld.so). The cache file defaults to/etc/ld.so.cache, which holds a list of queued dynamic-link library names.
(1) command format
ldconfig [Options] [Libs]
(2) main options
- V or--verbose ldconfig displays the directory being scanned, the dynamic link library that was searched, and the name of the connection it created.
- F CONF Specifies that the configuration file for the dynamic-link library is CONF and the system defaults to/etc/ld.so.conf.
The-c cache specifies that the generated cache file is cached, and the system defaults to/etc/ld.so.cache, which holds a list of queued, shareable, dynamic-link libraries.
- p or--print-cache let ldconfig print out the names of all shared libraries saved by the current cache file.
- R root changes the root directory of the application as root.
- N ldconfig scans only the directories specified by the command line, does not scan the default directory (/lib,/usr/lib), and does not scan the directories listed in the configuration file/etc/ld.so.conf.
when you run the Ldconfig command with no options, the cache file is updated. This command is primarily used for caching DNS servers (Caching DNS server). The principle of caching DNS servers is to provide a history of queries and to use these records to improve the efficiency of queries.
when a query is first sent to a cache DNS server, the caching DNS server records the entire process of the query and uses it to answer all the same queries for a certain period of time, reducing the burden on the entire DNS system and increasing the query speed.
(3) application examples
If the user wants to know what dynamic link libraries are in the system, or if they want to know if there is a dynamic link library in the system, the-p option allows ldconfig to output the list of dynamic-link libraries in the cache file to be queried. For example:
ldconfig-p
998 Libs found in cache '/etc/ld.so.cache '
libzvt.so.2 (LIBC6) =/usr/lib/libzvt.so.2
libzvt.so (LIBC6) =/usr/lib/libzvt.so
...
Add:
Compilation and use of static link library *.a
Create the. A library file and the. O Library file:
[Email protected] perl_c2]$ pwd
/home/yufei/perl_c2
[email protected] perl_c2]$ cat MYLIB.C
#include <stdio.h>
#include <string.h>
void Hello () {
printf ("Success call from Perl to C library\n");
}
[email protected] perl_c2]$ cat Mylib.h
extern void Hello ();
[Email protected] perl_c2]$ gcc-c MYLIB.C
[Email protected] perl_c2]$ dir
MYLIB.C Mylib.h MYLIB.O
[Email protected] perl_c2]$ ar-r MYLIB.A MYLIB.O
AR: Creating MYLIB.A
[Email protected] perl_c2]$ dir
MYLIB.A MYLIB.C mylib.h MYLIB.O
How to use *.A
The simplest is to compile the. A directly as a common source code.
GCC main.cpp./lib/libinfo.a-o exec
Compilation and use of dynamic link library *.so--
Dynamic library *.so is often encountered when programming with C and C + + under Linux, taking notes and providing a little help for other brothers who are distressed by the dynamic Library link library.
1, the compilation of dynamic library
Here's an example of how to build a dynamic library. Here is a header file: So_test.h, three. c Files: test_a.c, TEST_B.C, TEST_C.C, we compile these files into a dynamic library: libtest.so.
So_test.h:
#include <stdio.h>
#include <stdlib.h>
void Test_a ();
void Test_b ();
void Test_c ();
TEST_A.C:
#include "So_test.h"
void Test_a ()
{
printf ("This is intest_a...\n");
}
TEST_B.C:
#include "So_test.h"
void Test_b ()
{
printf ("This is intest_b...\n");
}
TEST_C.C:
#include "So_test.h"
void Test_c ()
{
printf ("This is intest_c...\n");
}
Compile these files into a dynamic library: libtest.so
$ gcc test_a.c test_b.c test_c.c-fpic-shared-o libtest.so
2, the dynamic library link
In 1, we have successfully generated a dynamic link library of our own libtest.so, below we have a program to invoke the function in this library. The source file for the program is: test.c.
TEST.C:
#include "So_test.h"
int main ()
{
Test_a ();
Test_b ();
Test_c ();
return 0;
}
L deliver test.c and dynamic library libtest.so to execute file test:
$ gcc test.c-l.-L TEST-O Test
L Test whether the connection is dynamic, if the libtest.so is listed, then it should be connected properly.
$ LDD Test
L Execute test and you can see how it calls functions in the dynamic library.
Summarize:
1, the shared library is particularly suitable for multiple programs to share code, upgrade the program part of the function module, the implementation of the program "plug-in" function;
While the static library is once and for all, after compiling does not need to carry a heap of library files to run, and no matter where they are placed to run normally.
2. When both the static and shared versions of the library exist under the search library file directory, the linker takes precedence over the shared version. So, you can use the-static link option to specify a static version of the link. A.
3, the dynamic library can export two special functions: _init and _fini, the former is called after the dynamic library is loaded, the latter is called before the dynamic library is unloaded.
We can use these two functions to do some special work. It is important to note that when you compile the two functions, you need to use the
The-nostartfiles option, or the compiler reports a duplicate definition error.
4. The LDD command is used to view the shared library on which the program depends, and it is convenient for us to determine if the shared library is found;
The NM command looks at the identity (function, variable) in the obj file (. So is also an obj).
This article is from the "Hollows Jie Sun" blog, be sure to keep this source http://xjsunjie.blog.51cto.com/999372/1917028
Study on Lib files under Linux