- Hands-On System Programming with C++
- Dr. Rian Quinn
- 199字
- 2021-07-02 14:42:32
Static libraries
Static libraries are a collection of object files that are linked at compile time. In Linux (and most UNIX-based systems), static libraries are nothing more than an archive of object files. You can easily take an existing static library and use the AR tool to extract the original object files.
Unlike object files that are linked as part of your program, object files that are linked as part of a static library only include the source code needed by that static library, providing optimization that removes unused code from your program, ultimately reducing the total size of your program.
The downside to this approach is that the order in which a program is linked using static libraries matters. If a library is linked before the code that needs the library is provided (on the command line, that is), a link error will occur, as the code from the static library will be optimized out.
Libraries provided by the operating system usually do not support static linking either, and, typically, static linking of operating system libraries is not needed as those libraries are likely to have been loaded into memory by your operating system.