In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the differences between dynamic libraries and static libraries in linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Differences: 1, the static library will be connected to the object code when the program is compiled, and the static library will no longer be needed when the program is running; the dynamic library will not be connected to the object code when the program is compiled, but will only be loaded when the program is running. therefore, the dynamic library still needs to exist when the program is running. 2. The files generated by the dynamic library are relatively small, while the files generated by the static library are relatively large.
The operating environment of this tutorial: CentOS 6 system, Dell G3 computer.
Similarities and differences between dynamic Library and static Library in linux
Similarities:
Both static and dynamic libraries are created by .o files. Therefore, we must first compile the source program into a .o file through gcc.
Difference:
1. Code loading time is different
The static library will be connected to the object code when the program is compiled, and the static library will no longer be needed when the program runs
The dynamic library is not connected to the object code when the program is compiled, but is loaded when the program is running, so the dynamic library still needs to exist when the program is running.
2. Different compilation rules
Dynamic library compilation
The name of the dynamic class library is generally libxxx.so, and the dynamic function library is not compiled into the object code at the time of compilation, and your program does not call the corresponding functions in the library until the relevant functions are executed, so the executable files generated by the dynamic function library are relatively small.
When dynamic libraries are compiled: the most important is an option on the GCC command line,-shared, which specifies that a dynamic link library is generated, for example:
Gmail +-shared-o libd1.so d1.o / * create a dynamic library file d1.so*/ based on the intermediate object file d1.o
Gmail +-shared-o libd2.so d2.o / * create a dynamic library file d2.so*/ based on the intermediate object file d2.o
Static library compilation
The name of the class library is generally libxxx.a; using the static function library to translate into a relatively large file, because all the data of the entire function library will be integrated into the object code, its advantages are obvious, that is, the compiled execution program does not need external function library support, because all the functions used have been compiled. Of course, this will also be his disadvantage, because if the static function library changes, then your program must be recompiled.
In UNIX, use the ar command to create or manipulate static libraries
Ar archivefile objfile
Archivefile:archivefile is the name of the static library
Objfile:objfile is an intermediate target file name with .o extension, which can be juxtaposed by multiple
For example:
Gmail +-o hello.o-c hello.cppar cqs libHello.a hello.o on "what is the difference between dynamic libraries and static libraries in linux" this article is shared here, 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, please 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: 267
*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.