Linux Dynamic and Static links 1. generate static Link Library gcc-c h. c-o h. o ar cqs libh. a h. o // ar is the command for generating the library, cqs is the parameter, libh. a is the generated static Link Library, which must start with lib, h is the database name, a is the static Link Library, h. o is the target file just generated 2. generate dynamic link library www.2cto.com gcc-c h. c-o h. o generate a dynamic link library and use gcc to complete gcc-shared-WI-o libh. so h. o //-shared-WI is the parameter, libh. so is the generated static Link Library, which must begin with lib, h is the library name, so is the dynamic link library, h. o is the target file generated just now. 3. the generated libh. a, libh. so copy to/usr/lib or/lib 4. compile the program gcc-c test with a static Link Library. c-o test. o gcc test. o-o test-WI-Bstatic-lh // -WI-Bstatic indicates the link to the static library,-l indicates the link in-lh, and h indicates the libh under the library name/usr/lib. a5. compile the program gcc-c test with dynamic link library. c-o test. o gcc test. o-o test-WI-Bdynamic-lh //-WI-Bdynamic indicates the link dynamic library, and-l indicates the link in-lh, h is the libh under/usr/lib. so6. run. /test to get the result www.2cto.com 7. other knowledge, such as libh. so.1.0, 1.0 indicates the version number. to use this library, you usually need to establish a soft connection, using ln-s libh. so.1.0 libh. so. the system does not know what 1.0 means. The dynamic and static link libraries must be used to compile the connection, and the following command is used: gcc test. o-o test-WI-Bstatic-lh1-WI-Bdynamic-lh2 8. the location of the dynamic or static library is located under/usr/lib or/lib. The system will automatically search for the dynamic or static library in these two directories when linking. If it is not in these two directories, modify the/etc/ld. so. conf file, write the directory to the file, and then ldconfig, and then OK. If the file is not stored in the usr/lib or/lib directory and the/etc/ld. so. conf file is not modified, you can add the-L/path during compilation. However, during execution, the system still prompts that the database cannot be found.
Author llg521208