Share static and dynamic libraries of C-language code, share static code Dynamics
Shared code can improve efficiency, but for code security and other reasons, c files are rarely retained. Instead, c files are compiled into. o files,
Share the code by sharing the H file and the. o file.
It is difficult to manage multiple. o files. If you package these files into a library, it is a common method to call the functions in the library through the Linked Library.
It is generally divided into static databases (archives) and dynamic databases.
Create an archive
The archive is a static library in the form of libxxx.. You can use the ar command to create an archive.
Ar-rcs libxxx. a. o B. o ......
Package a. o and B. o in the static library of libxxx..
Usage:
<1> put libxxx. a In the standard directory.
At this time, you do not need to specify the library file path gcc-lxxx to connect to the library.
<2> put libxxx. a in your own directory.
At this time, you need to specify the gcc-L/path/-lxxx library directory during compilation.
Create a dynamic library
Gcc-shared x. o-o libxxx. so (linux or unix) libxxx. dylib (mac)
Use the same static library.
On windows, how does one use C language to implement dynamic and static link libraries?
The link to the library is the function of the compiler. For example, vc uses a dynamic link to load the program into the memory and execute it.
Differences between dynamic and static connection libraries in C ++
The static link library is. files in lib format are generally added to the project on the project setting interface. The code of the lib file is added to your program during program compilation, so the code size is increased, the lib code of your program is forcibly loaded into the runtime space of your program. You cannot manually remove the lib code. The dynamic link library is a module dynamically loaded into the memory when the program is running. The format is *. dll. It can be loaded and removed at will when the program is running, saving memory space.
In large software projects, many functions are generally implemented. If all the functions are written as lib files, a large amount of memory space will be occupied during program running, resulting in slow operation; however, if you write a function as a dll file, you can call the dll file corresponding to the function when using this function. If you do not use this function, you can remove the dll file from the memory, which saves the memory space.