In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shares with you the content of a sample analysis of library files in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Recently, when using the third-party library Protobuf under Linux, I encountered a problem: the executable program was running an error: "error while loading shared libraries: libprotobuf.so.7: cannot open shared object file: No such file or directory". So take the time to figure out why, find a solution, and share it with you.
1. What is a library?
There are a large number of libraries in both windows platform and linux platform.
In essence, a library is a binary form of executable code that can be loaded into memory by the operating system.
Due to the different nature of windows and linux, the binaries of the two libraries are incompatible.
two。 Types of libraries
There are two kinds of libraries under linux: static libraries and shared libraries (dynamic libraries).
The difference between the two is that the code is loaded at different times.
The code of the static library has been loaded into the executable program during the compilation process, so it is larger. The code of the shared library is loaded into memory when the executable program is running, and there are only simple references during compilation, so the code is small. For the selection of static library and dynamic library, we need to consider the tradeoff between their advantages and disadvantages. Generally speaking, the more general libraries should be made into shared libraries.
3. The significance of the existence of the library
Libraries are existing, mature, reusable code written by others, and you can use them but remember to abide by the license agreement.
In reality, every program depends on many basic underlying libraries, and it is impossible for everyone's code to start from scratch, so the existence of the library is extraordinary. The advantage of a shared library is that if different applications call the same library, only one instance of the shared library is needed in memory.
4. How to generate library files under linux
The suffix of static library is .a, and its generation is divided into two steps.
Step 1: compiles a stack of .o from the source file, each of which contains a symbol table for this compilation unit
The Step 2:ar command converts a lot of .o to .a, which becomes a static library.
The dynamic library is suffixed with .so, which is compiled by gcc with specific parameters.
For example: $gcc-fPIC-c * .c $gcc-shared-Wl,-soname, libfoo.so.1-o libfoo.so.1.0 *.
5. How is the library file named? is there any specification?
Under linux, library files are generally placed under / usr/lib and / lib
The name of the static library is generally libxxxx.a, where xxxx is the name of the lib
The name of the dynamic library is generally libxxxx.so.major.minor,xxxx, which is the name of the lib, major is the major version number, and minor is the minor version number.
6. How to know which libraries an executable program depends on
The ldd command can view a shared library on which an executable program depends
For example # ldd / bin/lnlibc.so.6
= > / lib/libc.so.6 (0 × 40021000) / lib/ld-linux.so.2
= > / lib/ld- linux.so.2 (0 × 4000000)
You can see that the ln command depends on the libc library and the ld-linux library
7. How to locate shared library files when executable programs are executed
Static library: when the executable file is generated, the static library has been linked into the executable file as part of itself, so it does not need to be relocated during execution, that is, it is no longer dependent on the library file.
Dynamic library: you need to know the path to the dynamic library, refer to another blog
8. How to make the system find it after installing a new library
If installed under / lib or / usr/lib, ld can be found by default and no further action is required.
If you install it in a different directory, you need to add it to the / etc/ld.so.cache file as follows:
1. Edit the / etc/ld.so.conf file and add the path to the directory where the library file is located
two。 Run ldconfig, which rebuilds the / etc/ld.so.cache file
3. Root permission is required for ldconfig command
Thank you for reading! This is the end of this article on "sample Analysis of Library Files in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.